2010-11-12 How to debug with Android Logging
![AP Logger Architecture]
The above image shows the architecture of Android logging system.It provides a java class for logging named android.util.Log. It also provides log macros for native C applications in liblog.
There are four log devices in the kernel. Three for user space log: /dev/log/main
, /dev/log/radio
, /dev/log/events
. One for kernel space log: /dev/log/kernel
.
For user space applications, those binary log messages will be written to /dev/log/events
. Those log messages with the tag "HTC_RIL" "RILJ" "RILC" "RILD" "RIL" "AT" "GSM" "STK" will be written to /dev/log/radio
. Other log messages will be written to /dev/log/main
.
The log devices named /dev/log/kernel
is for kernel log message collection. A console is registered in /dev/log/kernel
and collect all the printk
output to the device. It will output kernel log messages with the same log format as other log devices.Logcat
is a tool provided by Android. It could read log messages from log devices and output to the console or to a file. You can find the detail usage later.
An aplog
daemon is added for offline log. A filter is added to do some security checking.
Logging interface For Java applications
Logging class Introduction
Class Name: android.util.Log
General method:
The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE
. VERBOSE
should never be compiled into an application except during development. DEBUG
logs are compiled in but stripped at runtime. ERROR
, WARN
and INFO
logs are always kept.
TIP: A good convention is to declare a TAG constant in your class:
private static final String TAG = "TAG_MyActivity";
>and use that in subsequent calls to the log methods.Log.v(TAG, "index=" + i);
When you're building the string to pass into Log.d, Java uses a StringBuilder and at least three allocations occur: the StringBuilder itself, the buffer, and the String object. Realistically, there is also another buffer allocation and copy, and even more pressure on the GC. That means that if your log message is filtered out, you might be doing significant work and incurring significant overhead.
For more details, please visit Android log reference
Program Example
Logging interface For Native applications
Header File include <cutils/log.h>
###Logging Macros
Common Logging Macros
Condition Logging Macros
The definition is as below:
Logging Macros overview
API for sending log output.
NOTE:
You should define LOG_TAG in your C source code firstly.
To build out C/C++ applications outside android, you should add
LOCAL_SHARED_LIBRARIES := liblog libcutils
in your Android.mk file
Program Example
Log command on Android
Command location
Command usage
priorityChar should be one of : v, d, i, w, e
## Log format on Android The format of a log messages is
tag: log tag
tv_sec & tv_nsec: the timestamp of the log messages
pid: the process id of where log messages come from
tid: the thread id
Priority value is one of the following character values, ordered from lowest to highest priority:
V - Verbose (lowest priority)*
D - Debug*
I - Info*
W - Warning*
E - Error*
F - Fatal*
S - Silent (highest priority, on which nothing is ever printed)*
最后更新于