Using and analyzing the Android log for debugging your apps and understanding how the system works.

In this post I’d like to get you familiar with the Android log system. This is a fundamental source of information about the behaviour of the system and that is frequently used in the software cycle development and it is extremely important when debugging your application or when customizing the Android ROM itsefl (in case you need Android to do advanced requirements).

Supposing you have an Android device, like for instance a smartphone or a tablet, the first and straighforward way to get more information about what’s happening behind the scenes, is to use your USB-to-MiniUSB cable and connect the device to the PC. If you have already installed the Android SDK, by typing the following command from the command line

[code language=”bash” collapse=”false”]
adb logcat
[/code]

you will immediately get some information about the system. An example of the output produced by the logcat on Android ICS is:

[sourcecode language=”shell” collapse=”false”]
I/SensorService( 2212): 3-axis Accelerometer
I/SensorService( 2212): Intersil isl29018 Ambient Light Sensor
I/SensorService( 2212): Intersil isl29018 Proximity sensor
I/SensorService( 2212): ADT7461 Temperature Monitor
I/sysproc ( 2212): System server: starting Android runtime.
I/sysproc ( 2212): System server: starting Android services.
I/sysproc ( 2212): System server: entering thread pool.
I/SystemServer( 2212): Entered the Android system server!
D/SensorService( 2212): nuSensorService thread starting…
I/SystemServer( 2212): Entropy Service
I/SystemServer( 2212): Power Manager
I/SystemServer( 2212): Activity Manager
I/ActivityManager( 2212): Memory class: 64
F/BatteryStatsImpl( 2212): problem reading network stats
F/BatteryStatsImpl( 2212): java.lang.IllegalStateException: problem parsing idx 1
F/BatteryStatsImpl( 2212): at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:300)
F/BatteryStatsImpl( 2212): at com.android.internal.net.NetworkStatsFactory.readNetworkStatsDetail(NetworkStatsFactory.java:250)
F/BatteryStatsImpl( 2212): at com.android.internal.os.BatteryStatsImpl.getNetworkStatsDetailGroupedByUid(BatteryStatsImpl.java:5734)
[/sourcecode]

Describing the Android log system in a couple of paragraphs is very difficult. However, you can think of it as the merge of different logging information available from diffent Android subsystems. The same Android log information is available on the DDMS perspective on Eclipse IDE.

eclipse ddms logcat

Android logcat is of utmost importance when developing new apps, however when you need to see what are the logging information of the kernel or kernel modules, you have to take other approaches. For instance, if you have an Android ICS, type the command:

[sourcecode language=”shell” collapse=”false”]
adb shell
[/sourcecode]

and when connected to the shell, type:

[sourcecode language=”shell” collapse=”false”]
dmesg
[/sourcecode]

you will get the low level logging information that are extremely important when developing your kernel modules or then dealing with special customization of the Android system.

[sourcecode language=”shell” collapse=”false”]
alarm_set_rtc: Failed to set RTC, time will be lost on reboot
request_suspend_state: wakeup (3->0) at 20282039697 (1970-01-02 00:00:04.371084282 UTC)
dm9000 dm9000: eth0: link down
ADDRCONF(NETDEV_UP): eth0: link is not ready
init: start ~~~~~~~~ dhcpcd_eth0:-h android-b729056a8fa357e eth0
acc_open
acc_release
mtp_open
init: cannot find ‘/system/busybox/bin/busybox’, disabling ‘preinstall’
init: start ~~~~~~~~ dhcpcd_eth0:-h android-b729056a8fa357e eth0
request_suspend_state: wakeup (0->0) at 45233170762 (1970-01-02 00:00:29.322215223 UTC)
init: untracked pid 2273 exited
[/sourcecode]

Every system is based on a special low-level code (called bootloader) that is executed when the system starts. Since there is no direct connection between the Android log system and the bootloader, these log information are displayed using another channel. To show you how to gather this log, we took this Android touch panel that use a serial port for outputting the bootloader status logs.

To do so:

Lascia un commento