How do you log to an Android device like system apps? - android

I would like to be able to save and print logcat messages when my device is disconnected from the computer, and then when I plug it in, to have all the messages be printed to logcat.
Currently, when I log, this does not happen. When I plug my phone in, I can hook the device to logcat and lots of logs from the day get printed into logcat. They are listed under my app's process. My logs are not there though. How can I get them there?
Here is how I log:
public static final String TAG = "Service";
Log.v(TAG, "log");
Edit: Yesterday, I disconnected from logcat with a process running. Then today, I reconnected to logcat. Since I still had a filter for my logs on, logs from the last few hours printed. I then turned the filter on and off and all of them disappeared.

You need to build a class that will be a wrapper for the android.util.Log class, that redirects the output to both file and console. Check this answer, it is a bit outdated but you can still follow the example and build such a class. This way you get the logs written to a file that you can check whenever you want.

You may save your logs to sharedpreferences and get it value after connection

Related

Android Studio 3.0 Logcat continuously showing messages and does not stop

When I start debugging my App in Android Studio 3.0 and open the Logcat, it displays so many messages and warnings, but the problem is, it never stops, even when the debugging is completed and the App is terminated, it still prints so many messages continuously.
Can anybody help???
Since you are not debugging or running any application on the device you have connected. Hence, the logcat is displaying the logs generated by all the apps in the device as well as the system logs. Which makes the log cat window go nuts.
What you can do is.
On the top right corner of the log cat window, there is a filter config combo box. Select or create a filter of your own to filter out relevant logs.
The filter could be created using any details, it could be a process ID (PID), the tag name e.g I/ActivityManager: where I stands for Info, V for Verbose, D for Debug and so on.
You can add filter in your Logcat, and mention all the classes whose logs you want to discard.
In the field LogTag (shown in the pic) define a regex like this ^(?!Class A | Class B|#). Here Class A and Class B are the classes whose logs you don't want to see.That's it.
If you see no debuggable application then change it to your app name. If that wont help change the log level to error. Last thing you can try is to filter the results. Good luck!

LogCat won't show my logs

I've searched for similar problems, but I didn't find anything useful - I'm working with eclipse, and I can't see my Logs.
The device is connected properly, the app runs and does what it's supposed to do, but I get no logs from it.
I get other logs messages from the device, not the ones that I print, e.g. Log.d("SMS", "hello"). On the other hand, if I use the statement System.out.println("hello"), I do see it, tagged as System.out.
I've tried to disconnect and reconnect the device, restart it, close and open eclipse, choose the device from Device window. It happens both with a 'real' device and an emulator. I've also tried to remove the filtering, but nothing helps - I still don't get the logs.
Okay, I've found the problem -
Apprently there are some illegal tags, and I've used one of them.
My app is spam SMS blocker, and I've used the tag SMS. If I change it to another tag (like SMSBlocker) it suddenly appears in the LogCat.
Check if your project is using proguard.
Basically proguard will remove all the debug logs and optimize your code while creating apk.
Try adding proguard.enabled=false in your project.properties
I think you should use TAG.
When you log from your android app, the first parameter is a TAG string. So if you set it up to a unique string (like your app name) then you can later filter by it in Eclipse.
Example : Log.e(TAG, "state error");

Eclipse Logcat goes crazy

I was using my Eclipse Logcat crazy normally until yesterday where it started displaying messages without stop.
My message that I am printing using log.d are no longer printed to the log.
Or maybe they are but because of the huge number of messages printed they are gone.
The messages do not stop printing to the log whether I am using the app or not.
The only way to stop it is to unplug my device from the PC otherwise the messages will keep flushing to the logcat
Any suggestions ?
Thanks in advance :)
It sounds like you have no filtering of the log output and therefor sees output for every app on the phone.
Create a logcat filter with your application package name.
In the logcat window, go to "Saved filters", create a new one (if Eclipse hasnĀ“t autocreated one for you) by clicking plus-sign to add. Type a name of your filter and write your application package name under "by Application Name". Click "ok".
When you select it you only see logcat outputs for your specified app.

Whats wrong with my Eclipse or phone?

When I connect my phone when Eclipse is running, in the LogCat it continues to write something without end, and prints some error messages all the time "Fatal signal something", whats wrong? Here's part of the log, it's still printing and doesn't sime like it will stop soon
http://pastebin.com/4Z58CiGm
These are all logs from system apps and processes, and you can safely ignore them.
You should tag all the statements from your app using:
Log.d("MyAwesomeTag", "Message");
Then you can filter them using tag:MyAwesomeTag and ignore everything that isn't yours

Logcat output of my app vanished from logcat output

i have a problem with logcat output of my app:
Normally logging to logcat works. But at some times my app's output seems to be entirely removed from the logcat output. Though i can prove that the app logged, there is not a single line in logcat.
When does this happen:
I shedule my app to wakeup at midnight by a BroadcastReceiver starting a Service. The app wakes up and creates a logfile, writes to that file and to logcat in parallel by calling a function which writes to both. The logfile contains 3 lines written. (and then the app somehow dies.) At least these 3 lines have been also logged to logcat.
Next day i display all logcat messages, which encloses midnight. Not a single line logged for my app.
I think Android has purged my App from memory and at midnight it is loaded again (and crashes because it is not initialized properly). But why is there no logcat output?
thanks for your hint.
Logcat has a size limit. Once this limit is reached, older messages are purged to make room for the new ones coming in. It's not that Logcat is removing your app's messages specifically, it's that in the course of running over night there are so many other messages going to Logcat that yours are being removed.
To see the buffer size on your specific device, plug it in and execute the following command in a shell window:
adb logcat -g
If you need to collect log messages at a time where you can't physically be looking at the output window, you're doing the right thing by logging to a file. I do something similar where I'll set a global flag on the build that tells it whether to log normally or output to a local file on my phone.

Categories

Resources