logcat
The Android log reading tool is named logcat. This application is available on all Android devices.
A good overview of using logcat is at http://developer.android.com/guide/developing/tools/adb.html#logcat. Please get familiar with this useful tool first.
logcat provides logs:
- from all the running Android applications (thanks to 4 logcat user space buffers)
- system
- main
- radio (for modem interface logs)
- events
Android loglevel
- There are different log level in Android : VERBOSE, DEBUG, INFO, WARN, ERROR, ASSERT, or SUPPRESS
- A different TAG per application is used, and the log level can be changed for each TAG with different method depending on how it is implemeted in the code.
- The default log level is INFO.
Dynamic log level implementation
- If implemented dynamically in Java with isLoggable, you can use :
adb shell setprop log.tag.<YOUR_LOG_TAG> <LEVEL>
or you can also create a local.prop file with the following in it: 'log.tag.<YOUR_LOG_TAG>=<LEVEL>' and place that in /data/local.prop, and reboot to apply.
adb shell # echo "log.tag.<YOUR_LOG_TAG>=<LEVEL>" >> /data/local.prop # reboot
Static log level implementation
- If implemented statically in C/C++ or Java :
You need to check the code to know how the logging is implemented in the application.
Here is an example to enable verbose logs (logv) in a C/C++ application
- Those files already has these lines included to support LOGV:
#include <log.h> #define LOG_TAG "tag_name" //#define LOG_NDEBUG 0 LOGV() function call at multiple places
- To see LOGV ouputs, you simply need to uncomment the #define LOG_NDEBUG 0 line. After that, rebuilt your image, boot to image again, and logcat would output logv messages.
Redirect stdout to logcat
- For Java/Android applications using System.out calls :
% adb shell setprop log.redirect-stdio true To just view stdout output in logcat: % adb logcat System.out:I *:S
- For native applications, you should use logwrapper
root@android:/ # logwrapper Usage: logwrapper [-d] BINARY [ARGS ...] Forks and executes BINARY ARGS, redirecting stdout and stderr to the Android logging system. Tag is set to BINARY, priority is always LOG_INFO. -d: Causes logwrapper to SIGSEGV when BINARY terminates fault address is set to the status of wait()
Simple use to redirect getevent output to logs :
# logwrapper getevent
Print your message in logs
This could be really usefull to print your own message in logs from a shell to get temporal markers of what you have done.
root@android:/ # log USAGE: log [-p priorityChar] [-t tag] message priorityChar should be one of: v,d,i,w,e
Simple example :
# log -p i -t MY_TAG "doing a test"
And you will get this in logs :
02-01 13:35:06.890 12746 12746 I MY_TAG : doing a test