John Glen
John Glen

Reputation: 951

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

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.

Upvotes: 0

Views: 276

Answers (2)

therock24
therock24

Reputation: 159

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.

Upvotes: 2

Ann Developer
Ann Developer

Reputation: 155

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

Upvotes: 0

Related Questions