SlideShare a Scribd company logo
Anroid Logging System
William.L
wiliwe@gmail.com
Date: 2011-07-21
Outline
Overview of Android Loggin System
Log from Java program
Log from Native C/C++ program
How to read log?
Tips
Overview of Android
Logging System
What is Android Logging System?
Provide a mechanism for collecting and viewing
system debug output
Logs from various applications and portions of
the system are collected in a series of circular
buffers, which then can be viewed and filtered by
the logcat command
Overview of Logging System
[Android Device]
[HOST/PC]
USB
cable
Introduction
The logging system consists of
A kernel driver and kernel buffers for storing log messages
HoneycombMR2Src/kernel/drivers/staging/android/logger.c
Create “/dev/log” folder in handle_device_event() of
AndroidSrc/system/core/init/devices.c
C/C++/Java APIs and classes
For making log messages
For accessing the log messages
logcat, the command for viewing log messages
AndroidSrc/system/core/logcat/
Ability to view and filter the log messages from the host
machine (via Eclipse-ADT or DDMS)
Log device files
4 channels, each have a Ring/Circular Buffer
/dev/log/radio – radio&phone-related messages (64KB)
/dev/log/events – system/hardware events (256KB)
/dev/log/system –framwork or low-level system messages
(64KB)
/dev/log/main – everything else (64KB)
The maximum log message size of each channel is specified in
kernel driver(logger.c)
File permission of each(radio/events/system/main) is
0662 (rw-rw-w)
owner/group RW,
other Write only
owner=root, group=log
Anyone can Write logs, root or log group can Read them
Android Debug Bridge
ADB client
Runs on your development machine(Host).
You can invoke a client from a shell by issuing an “adb”
command.
Other Android tools such as the ADT plugin and DDMS also
create adb clients.
ADB server (adbserver)
Runs on your development machine(Host).
The server manages communication between the client and the
adb daemon running on an emulator or device.
ADB daemon (adbd)
Runs on each Android emulator or Android device instance.
Log from Java program
Classes used for Logging
android.util.Log class
System.out / System.err
android.util.Log
Static methods
AndroidSrc/frameworks/base/core/java/android/util/Log.
java
Error messageLog.e (String tag, String msg)
Warrning messageLog.w (String tag, String msg)
Info messageLog.i (String tag, String msg)
Debugging messageLog.d (String tag, String msg)
Verbose messageLog.v (String tag, String msg)
Example :
/* In Java code, add the following codes */
import android.util.Log;
class CCLLAASS {
static String TAG=“tagName”;
public MethodXX() {
Log.v(TAG, “Debugging messages you want”);
}
}
System.out / System.err (1/2)
System.out/System.err output to Android log
zygoteInit() {
System.setOut(AndroidPrintStream);
System.setErr(AndroidPrintStream); }
AndroidSrc/frameworks/base/core/java/com/android/internal/o
s/RuntimeInit.java
com.android.internal.os.AndroidPrintStream (which derives
from LoggingPrintStream which derives from
PrintStream)
AndroidSrc/frameworks/base/core/java/com/android/internal/o
s/AndroidPrintStream.java
System.out / System.err (2/2)
How to identify instance of System.out/System.err?
System.out.println(”System.out=”+System.out.toString())
System.err.println(”System.err=”+System.err.toString())
Example :
/* Add the System.out and System.err statements in the constructor of MountService.java */
class MountService {
MountService() {
….
System.out.println(”System.out’s instance is ”+System.out.toString());
System.err.println(”System.err’s instance is ”+System.err.toString());
….
}
}
Log from Native C/C++
program
Library for Logging
Use liblog library
Include <android/log.h> header
<cutils/log.h>(libcutils) header could be used
This header includes <android/log.h> eventually
__android_log_print macro(defined in liblog) is the
actual worker behind LOGI[V/D/W/E] functions
Example :
#define LOGI(...) 
__android_log_print (ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
Usage :
LOGI(”i=%d, name=%sn”, i, name);
Log From Native Program (1/2)
Log functions
Error messageLOGE (String msg)
Warrning messageLOGW (String msg)
Info messageLOGI (String msg)
Debugging messageLOGD (String msg)
Verbose message.LOGV (String msg)
Example :
/* In C/C++ code, add the following codes*/
#define LOG_TAG “tagName”
#include <cutils/log.h>
LOGV(“Debugging messages you want”);
Log From Native Program (2/2)
It must add following definition BEFORE the header
"#include <cutils/log.h>"
#undef NDEBUG : Enable LOGV/LOGI/LOGD
#define LOG_NDEBUG 0 : Enable LOGV
#define LOG_NIDEBUG 0 : Enable LOGI
#define LOG_NDDEBUG 0 : Enable LOGD
#define LOG_TAG “String-You-Want"
Because all the above are defined in <cutils/log.h>,
if the define is put after the header including
statment, it will show “redefined” compile warning
and define will not take effect
How to read log?
Logcat Command
“logcat” command runs on Android device
Use the command to run ‘logcat’ command on
the remote Android device : “adb shell logcat”
ADB Logcat
Command : adb logcat
Logcat pane in ADT, Eclipse
Tips
Dumping stack trace
logwrapper
Log at ‘init’ process
Support Non built-in ADB USB VID
Dumping stack trace (1/2)
3 arguments methods in android.util.Log class
Ex: Log.e(String tag, String msg, new Throwable())
Throwable.printStacktrace() also works
Dump to System.err
Dumping stack trace (2/2)
Example for Throwable.printStackTrace (MountService.java) :
class MountService extends IMountService.Stub implements INativeDaemonConnectorCallbacks
{
public static void NewException() throws Throwable
{
throw new Throwable("New Exception...");
}
public MountSerivce(Context context) {
…
try {
NewException();
} catch (Throwable e) {
// Prints this throwable and its backtrace to the
// standard error stream.
e.printStackTrace();
}
...
}
…
}
logwrapper
Redirects stdout(like printf)/stderr to Android
Logging system
Usage
“logwrapper Executable”, and use “logcat” to watch logs as
usual
Ex : “logwrapper ObbFile_test”
Executing without ‘logwrapper’ Executing with ‘logwrapper’
Log at init process
The first process, 'init‘, does not use Android
Logging System.
‘init’ writes log to (the same node as) '/dev/kmsg'
The same way as 'printk()'
Add a command in init.rc to write Android logs to
kernel logging file, /dev/kmsg
Command :
Watch logs : run “adb shell dmesg” on the host
Shortpoint : duplicated store of Android log
To save output messages of logcat
logcat -f fileName
service logcat /system/bin/logcat -f /dev/kmsg
oneshot
Support Non built-in ADB USB VID (1/2)
ADB built-in USB VID
http://developer.android.com/guide/developing/device.html
#VendorIds
Solution-1 : Append the new USB VID into the
adb_usb.ini file
Commands (executing on the host, e.g.PC/NB) :
Create the folder/file ‘~/.android/adb_usb.ini’ if it does not
exist
‘adb’ command reads and checks content of this file each time it
is executed
echo "New-Vendor-ID" >> ~/.android/adb_usb.ini
sudo -s "adb kill-server;adb start-server“
Example (Lenovo VID : 0x17EF) :
/* It can watch the VID of an Android device
using ‘lsusb’ command under the host */
#> echo "0x17EF" >> ~/.android/adb_usb.ini
#> sudo -s "adb kill-server;adb start-server"
Support Non built-in ADB USB VID (2/2)
Solution-2 : Build a new ‘adb’ tool supporting new
VID
In AndroidSrc/system/core/adb/usb_vendors.c
#define VENDOR-NAME Vendor-ID
Add an entry with new VENDOR-NAME in variable
builtInVendorIds[] and then compile ‘adb’ sources
Built new ‘adb’ exectuable is under the folder :
out/host/linux-x86/bin/
Ex - In AndroidSrc/system/core/adb/usb_vendors.c :
// Lenovo's USB Vendor ID
#define VENDOR_ID_LENOVO 0x17EF
/** built-in vendor list */
int builtInVendorIds[] = {
....... ,
VENDOR_ID_LENOVO
};
Reference
http://elinux.org/Android_Logging_System
Android Logging system slide -
http://blog.kmckk.com/archives/2936958.html
logwrapper -
http://blog.kmckk.com/archives/2918551.html
Print Call Stack -
http://blog.kmckk.com/archives/2902690.html

More Related Content

What's hot (20)

PDF
Booting Android: bootloaders, fastboot and boot images
Chris Simmonds
 
PPT
Learning AOSP - Android Booting Process
Nanik Tolaram
 
PDF
Logging system of Android
Tetsuyuki Kobayashi
 
PDF
Android Security Internals
Opersys inc.
 
PPTX
Binder: Android IPC
Shaul Rosenzwieg
 
PDF
Android device driver structure introduction
William Liang
 
PPTX
Android Binder: Deep Dive
Zafar Shahid, PhD
 
PDF
Android Storage - Vold
William Lee
 
PPTX
Android Booting Sequence
Jayanta Ghoshal
 
PPT
Android booting sequece and setup and debugging
Utkarsh Mankad
 
PDF
Accessing Hardware on Android
Gary Bisson
 
PDF
Android Storage - StorageManager & OBB
William Lee
 
PDF
Understanding the Android System Server
Opersys inc.
 
PPTX
Android internals By Rajesh Khetan
Rajesh Khetan
 
PDF
Android IPC Mechanism
National Cheng Kung University
 
PDF
Embedded Android : System Development - Part IV (Android System Services)
Emertxe Information Technologies Pvt Ltd
 
PDF
OpenWrt From Top to Bottom
Kernel TLV
 
PDF
Embedded Android : System Development - Part II (HAL)
Emertxe Information Technologies Pvt Ltd
 
PDF
Android Internals
Opersys inc.
 
Booting Android: bootloaders, fastboot and boot images
Chris Simmonds
 
Learning AOSP - Android Booting Process
Nanik Tolaram
 
Logging system of Android
Tetsuyuki Kobayashi
 
Android Security Internals
Opersys inc.
 
Binder: Android IPC
Shaul Rosenzwieg
 
Android device driver structure introduction
William Liang
 
Android Binder: Deep Dive
Zafar Shahid, PhD
 
Android Storage - Vold
William Lee
 
Android Booting Sequence
Jayanta Ghoshal
 
Android booting sequece and setup and debugging
Utkarsh Mankad
 
Accessing Hardware on Android
Gary Bisson
 
Android Storage - StorageManager & OBB
William Lee
 
Understanding the Android System Server
Opersys inc.
 
Android internals By Rajesh Khetan
Rajesh Khetan
 
Android IPC Mechanism
National Cheng Kung University
 
Embedded Android : System Development - Part IV (Android System Services)
Emertxe Information Technologies Pvt Ltd
 
OpenWrt From Top to Bottom
Kernel TLV
 
Embedded Android : System Development - Part II (HAL)
Emertxe Information Technologies Pvt Ltd
 
Android Internals
Opersys inc.
 

Viewers also liked (20)

PDF
ADB(Android Debug Bridge): How it works?
Tetsuyuki Kobayashi
 
PPTX
Android - ADB
Yossi Gruner
 
PDF
Effortless network response logging on Android
Simon Percic
 
PDF
GNOME GeoClue - The Geolocation Service in Gnome
William Lee
 
PDF
Android Debugging (Chinese)
William Lee
 
PDF
Android Services and Managers Basic
William Lee
 
PDF
Moblin2 - Window Manager(Mutter) Plugin
William Lee
 
PDF
Usage Note of Qt ODBC Database Access on Linux
William Lee
 
PDF
Introdunction To Network Management Protocols SNMP & TR-069
William Lee
 
PDF
CWMP TR-069 Training (Chinese)
William Lee
 
PDF
Qt Development Tools
William Lee
 
PDF
Android internals
Liran Ben Haim
 
PDF
Asterisk (IP-PBX) CDR Log Rotation
William Lee
 
PDF
IPv6 Overview
William Lee
 
PPTX
Google android Activity lifecycle
University of Potsdam
 
PPTX
The android activity lifecycle
Eng Chrispinus Onyancha
 
PDF
MGCP Overview
William Lee
 
PPTX
Android Activity Transition(ShareElement)
Ted Liang
 
PDF
Android Storage - Internal and External Storages
William Lee
 
PDF
Android life cycle
瑋琮 林
 
ADB(Android Debug Bridge): How it works?
Tetsuyuki Kobayashi
 
Android - ADB
Yossi Gruner
 
Effortless network response logging on Android
Simon Percic
 
GNOME GeoClue - The Geolocation Service in Gnome
William Lee
 
Android Debugging (Chinese)
William Lee
 
Android Services and Managers Basic
William Lee
 
Moblin2 - Window Manager(Mutter) Plugin
William Lee
 
Usage Note of Qt ODBC Database Access on Linux
William Lee
 
Introdunction To Network Management Protocols SNMP & TR-069
William Lee
 
CWMP TR-069 Training (Chinese)
William Lee
 
Qt Development Tools
William Lee
 
Android internals
Liran Ben Haim
 
Asterisk (IP-PBX) CDR Log Rotation
William Lee
 
IPv6 Overview
William Lee
 
Google android Activity lifecycle
University of Potsdam
 
The android activity lifecycle
Eng Chrispinus Onyancha
 
MGCP Overview
William Lee
 
Android Activity Transition(ShareElement)
Ted Liang
 
Android Storage - Internal and External Storages
William Lee
 
Android life cycle
瑋琮 林
 
Ad

Similar to Android Logging System (20)

PPT
.NET Debugging Tips and Techniques
Bala Subra
 
PPT
.Net Debugging Techniques
Bala Subra
 
ODP
Android porting for dummies @droidconin 2011
pundiramit
 
PPT
Android developmenttools 20100424
Marakana Inc.
 
ODP
Android basics
Berglind Ósk Bergsdóttir
 
PPTX
Android tools for testers
Maksim Kovalev
 
PDF
Working with the AOSP - Linaro Connect Asia 2013
Opersys inc.
 
ODP
Q4.11: Porting Android to new Platforms
Linaro
 
PPT
Life of a Chromium Developer
mpaproductions
 
PDF
lecture-2-android-dev.pdf
jakjak36
 
PDF
Advanced iOS Debbuging (Reloaded)
Massimo Oliviero
 
PPTX
Google Cloud Build - Overview and Examples
Evgenii Studitskikh
 
PDF
Android OS Porting: Introduction
Jollen Chen
 
PPTX
Using the android ndk - DroidCon Paris 2014
Paris Android User Group
 
PDF
Eric Lafortune - Fighting application size with ProGuard and beyond
GuardSquare
 
PDF
Eric Lafortune - Fighting application size with ProGuard and beyond
GuardSquare
 
PDF
Android Internals
Opersys inc.
 
PPT
Android dev
yincan sheng
 
PDF
Debugging Python with gdb
Roman Podoliaka
 
PDF
Android Attacks
Michael Scovetta
 
.NET Debugging Tips and Techniques
Bala Subra
 
.Net Debugging Techniques
Bala Subra
 
Android porting for dummies @droidconin 2011
pundiramit
 
Android developmenttools 20100424
Marakana Inc.
 
Android tools for testers
Maksim Kovalev
 
Working with the AOSP - Linaro Connect Asia 2013
Opersys inc.
 
Q4.11: Porting Android to new Platforms
Linaro
 
Life of a Chromium Developer
mpaproductions
 
lecture-2-android-dev.pdf
jakjak36
 
Advanced iOS Debbuging (Reloaded)
Massimo Oliviero
 
Google Cloud Build - Overview and Examples
Evgenii Studitskikh
 
Android OS Porting: Introduction
Jollen Chen
 
Using the android ndk - DroidCon Paris 2014
Paris Android User Group
 
Eric Lafortune - Fighting application size with ProGuard and beyond
GuardSquare
 
Eric Lafortune - Fighting application size with ProGuard and beyond
GuardSquare
 
Android Internals
Opersys inc.
 
Android dev
yincan sheng
 
Debugging Python with gdb
Roman Podoliaka
 
Android Attacks
Michael Scovetta
 
Ad

More from William Lee (20)

PDF
Usage Note of Apache Thrift for C++ Java PHP Languages
William Lee
 
PDF
Usage Note of SWIG for PHP
William Lee
 
PDF
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
William Lee
 
PDF
Usage Notes of The Bro 2.2 / 2.3
William Lee
 
PDF
Viewing Android Source Files in Eclipse (Chinese)
William Lee
 
PDF
Usage Note of Microsoft Dependency Walker
William Lee
 
PDF
Usage Note of PlayCap
William Lee
 
PDF
Qt4 App - Sliding Window
William Lee
 
PDF
GTK+ 2.0 App - Desktop App Chooser
William Lee
 
PDF
GTK+ 2.0 App - Icon Chooser
William Lee
 
PDF
Note of CGI and ASP
William Lee
 
PDF
L.A.M.P Installation Note --- CentOS 6.5
William Lee
 
PDF
C Program Runs on Wrong Target Platform(CPU Architecture)
William Lee
 
PDF
Internationalization(i18n) of Web Page
William Lee
 
PDF
Notes for SQLite3 Usage
William Lee
 
PDF
Cygwin Install How-To (Chinese)
William Lee
 
PDF
Study of Chromium OS
William Lee
 
PDF
More Details about TR-069 (CPE WAN Management Protocol)
William Lee
 
PDF
Introdunction to Network Management Protocols - SNMP & TR-069
William Lee
 
PDF
Qt Animation
William Lee
 
Usage Note of Apache Thrift for C++ Java PHP Languages
William Lee
 
Usage Note of SWIG for PHP
William Lee
 
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
William Lee
 
Usage Notes of The Bro 2.2 / 2.3
William Lee
 
Viewing Android Source Files in Eclipse (Chinese)
William Lee
 
Usage Note of Microsoft Dependency Walker
William Lee
 
Usage Note of PlayCap
William Lee
 
Qt4 App - Sliding Window
William Lee
 
GTK+ 2.0 App - Desktop App Chooser
William Lee
 
GTK+ 2.0 App - Icon Chooser
William Lee
 
Note of CGI and ASP
William Lee
 
L.A.M.P Installation Note --- CentOS 6.5
William Lee
 
C Program Runs on Wrong Target Platform(CPU Architecture)
William Lee
 
Internationalization(i18n) of Web Page
William Lee
 
Notes for SQLite3 Usage
William Lee
 
Cygwin Install How-To (Chinese)
William Lee
 
Study of Chromium OS
William Lee
 
More Details about TR-069 (CPE WAN Management Protocol)
William Lee
 
Introdunction to Network Management Protocols - SNMP & TR-069
William Lee
 
Qt Animation
William Lee
 

Recently uploaded (20)

PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 

Android Logging System

  • 2. Outline Overview of Android Loggin System Log from Java program Log from Native C/C++ program How to read log? Tips
  • 4. What is Android Logging System? Provide a mechanism for collecting and viewing system debug output Logs from various applications and portions of the system are collected in a series of circular buffers, which then can be viewed and filtered by the logcat command
  • 5. Overview of Logging System [Android Device] [HOST/PC] USB cable
  • 6. Introduction The logging system consists of A kernel driver and kernel buffers for storing log messages HoneycombMR2Src/kernel/drivers/staging/android/logger.c Create “/dev/log” folder in handle_device_event() of AndroidSrc/system/core/init/devices.c C/C++/Java APIs and classes For making log messages For accessing the log messages logcat, the command for viewing log messages AndroidSrc/system/core/logcat/ Ability to view and filter the log messages from the host machine (via Eclipse-ADT or DDMS)
  • 7. Log device files 4 channels, each have a Ring/Circular Buffer /dev/log/radio – radio&phone-related messages (64KB) /dev/log/events – system/hardware events (256KB) /dev/log/system –framwork or low-level system messages (64KB) /dev/log/main – everything else (64KB) The maximum log message size of each channel is specified in kernel driver(logger.c) File permission of each(radio/events/system/main) is 0662 (rw-rw-w) owner/group RW, other Write only owner=root, group=log Anyone can Write logs, root or log group can Read them
  • 8. Android Debug Bridge ADB client Runs on your development machine(Host). You can invoke a client from a shell by issuing an “adb” command. Other Android tools such as the ADT plugin and DDMS also create adb clients. ADB server (adbserver) Runs on your development machine(Host). The server manages communication between the client and the adb daemon running on an emulator or device. ADB daemon (adbd) Runs on each Android emulator or Android device instance.
  • 9. Log from Java program
  • 10. Classes used for Logging android.util.Log class System.out / System.err
  • 11. android.util.Log Static methods AndroidSrc/frameworks/base/core/java/android/util/Log. java Error messageLog.e (String tag, String msg) Warrning messageLog.w (String tag, String msg) Info messageLog.i (String tag, String msg) Debugging messageLog.d (String tag, String msg) Verbose messageLog.v (String tag, String msg) Example : /* In Java code, add the following codes */ import android.util.Log; class CCLLAASS { static String TAG=“tagName”; public MethodXX() { Log.v(TAG, “Debugging messages you want”); } }
  • 12. System.out / System.err (1/2) System.out/System.err output to Android log zygoteInit() { System.setOut(AndroidPrintStream); System.setErr(AndroidPrintStream); } AndroidSrc/frameworks/base/core/java/com/android/internal/o s/RuntimeInit.java com.android.internal.os.AndroidPrintStream (which derives from LoggingPrintStream which derives from PrintStream) AndroidSrc/frameworks/base/core/java/com/android/internal/o s/AndroidPrintStream.java
  • 13. System.out / System.err (2/2) How to identify instance of System.out/System.err? System.out.println(”System.out=”+System.out.toString()) System.err.println(”System.err=”+System.err.toString()) Example : /* Add the System.out and System.err statements in the constructor of MountService.java */ class MountService { MountService() { …. System.out.println(”System.out’s instance is ”+System.out.toString()); System.err.println(”System.err’s instance is ”+System.err.toString()); …. } }
  • 14. Log from Native C/C++ program
  • 15. Library for Logging Use liblog library Include <android/log.h> header <cutils/log.h>(libcutils) header could be used This header includes <android/log.h> eventually __android_log_print macro(defined in liblog) is the actual worker behind LOGI[V/D/W/E] functions Example : #define LOGI(...) __android_log_print (ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) Usage : LOGI(”i=%d, name=%sn”, i, name);
  • 16. Log From Native Program (1/2) Log functions Error messageLOGE (String msg) Warrning messageLOGW (String msg) Info messageLOGI (String msg) Debugging messageLOGD (String msg) Verbose message.LOGV (String msg) Example : /* In C/C++ code, add the following codes*/ #define LOG_TAG “tagName” #include <cutils/log.h> LOGV(“Debugging messages you want”);
  • 17. Log From Native Program (2/2) It must add following definition BEFORE the header "#include <cutils/log.h>" #undef NDEBUG : Enable LOGV/LOGI/LOGD #define LOG_NDEBUG 0 : Enable LOGV #define LOG_NIDEBUG 0 : Enable LOGI #define LOG_NDDEBUG 0 : Enable LOGD #define LOG_TAG “String-You-Want" Because all the above are defined in <cutils/log.h>, if the define is put after the header including statment, it will show “redefined” compile warning and define will not take effect
  • 18. How to read log?
  • 19. Logcat Command “logcat” command runs on Android device Use the command to run ‘logcat’ command on the remote Android device : “adb shell logcat”
  • 20. ADB Logcat Command : adb logcat
  • 21. Logcat pane in ADT, Eclipse
  • 22. Tips Dumping stack trace logwrapper Log at ‘init’ process Support Non built-in ADB USB VID
  • 23. Dumping stack trace (1/2) 3 arguments methods in android.util.Log class Ex: Log.e(String tag, String msg, new Throwable()) Throwable.printStacktrace() also works Dump to System.err
  • 24. Dumping stack trace (2/2) Example for Throwable.printStackTrace (MountService.java) : class MountService extends IMountService.Stub implements INativeDaemonConnectorCallbacks { public static void NewException() throws Throwable { throw new Throwable("New Exception..."); } public MountSerivce(Context context) { … try { NewException(); } catch (Throwable e) { // Prints this throwable and its backtrace to the // standard error stream. e.printStackTrace(); } ... } … }
  • 25. logwrapper Redirects stdout(like printf)/stderr to Android Logging system Usage “logwrapper Executable”, and use “logcat” to watch logs as usual Ex : “logwrapper ObbFile_test” Executing without ‘logwrapper’ Executing with ‘logwrapper’
  • 26. Log at init process The first process, 'init‘, does not use Android Logging System. ‘init’ writes log to (the same node as) '/dev/kmsg' The same way as 'printk()' Add a command in init.rc to write Android logs to kernel logging file, /dev/kmsg Command : Watch logs : run “adb shell dmesg” on the host Shortpoint : duplicated store of Android log To save output messages of logcat logcat -f fileName service logcat /system/bin/logcat -f /dev/kmsg oneshot
  • 27. Support Non built-in ADB USB VID (1/2) ADB built-in USB VID http://developer.android.com/guide/developing/device.html #VendorIds Solution-1 : Append the new USB VID into the adb_usb.ini file Commands (executing on the host, e.g.PC/NB) : Create the folder/file ‘~/.android/adb_usb.ini’ if it does not exist ‘adb’ command reads and checks content of this file each time it is executed echo "New-Vendor-ID" >> ~/.android/adb_usb.ini sudo -s "adb kill-server;adb start-server“ Example (Lenovo VID : 0x17EF) : /* It can watch the VID of an Android device using ‘lsusb’ command under the host */ #> echo "0x17EF" >> ~/.android/adb_usb.ini #> sudo -s "adb kill-server;adb start-server"
  • 28. Support Non built-in ADB USB VID (2/2) Solution-2 : Build a new ‘adb’ tool supporting new VID In AndroidSrc/system/core/adb/usb_vendors.c #define VENDOR-NAME Vendor-ID Add an entry with new VENDOR-NAME in variable builtInVendorIds[] and then compile ‘adb’ sources Built new ‘adb’ exectuable is under the folder : out/host/linux-x86/bin/ Ex - In AndroidSrc/system/core/adb/usb_vendors.c : // Lenovo's USB Vendor ID #define VENDOR_ID_LENOVO 0x17EF /** built-in vendor list */ int builtInVendorIds[] = { ....... , VENDOR_ID_LENOVO };
  • 29. Reference http://elinux.org/Android_Logging_System Android Logging system slide - http://blog.kmckk.com/archives/2936958.html logwrapper - http://blog.kmckk.com/archives/2918551.html Print Call Stack - http://blog.kmckk.com/archives/2902690.html