Android Log Analysis

Android logs caption

As an Android developer, all of you know Logs analysis is a phase of development and we encounter it from time to time.
But Log Analysis is the main challenging thing for code maintainer or Support Engineer.

Once Any Android product launched in the market and customers start using it. Then real scenario bugs/issues start coming and it is the main Job for Support Engineer/Project maintenance engineer to analyze the Bug/issue with provided set of logs.

First We start with the type of Log available on Android Eco-system:-

  • Application Log
  • System Log
  • Event Log
  • Radio Log

Android logging system consists of:

  • a kernel driver and kernel buffers for storing log messages
  • C, C++ and Java classes for making log entries and accessing the log messages.
  • Logcat (a standalone program for viewing log messages )
  • DDMS (ability to view and filter the log messages from the host machine)

Android Log Buffer/container

  • main — the main application log
  • events — for system event information
  • radio — for radio and phone-related information
  • system — a log for low-level system messages and debugging

What Log message contains:-

Each message in the log consists of

  • A tag indicating the part of the system or application that the message came from
  • A timestamp (at what time this message came)
  • The message log level (or priority of the event represented by the message) and
  • The log message itself(detail description of error or exception or information etc)

What Each Log Type Contains:-

1. Application log

  • use android.util.Log class methods to write messages of different priority into the log
  • Java classes declare their tag statically as a string, which they pass to the log method
  • The log method used indicates the message “severity” (or log level)
  • Messages can be filtered by tag or priority when the logs are processed by retrieval tools (logcat)

2. System log

  • Use the android.util.Slog class to write a message with different priority with its associated messages
  • Many Android framework classes utilize the system log to keep their messages separate from (possibly noisy) application log messages
  • A formatted message is delivered through the C/C++ library down to the kernel driver, which stores the message in the appropriate buffer(system buffer)

3. Event log

  • Event logs messages are created using android.util.EventLog class, which creates binary-formatted log messages.
  • Log entries consist of binary tag codes, followed by binary parameters.
  • The message tag codes are stored on the system at: /system/etc/event-log-tags.
  • Each message has the string for the log message, as well as codes indicating the values associated with (stored with) that entry.

4. Radio log

  • Used for radio and phone(modem) related information
  • Log entries consist of binary tags code and message for Network info
  • Logging system automatically routes messages with specific tags into the radio buffer

Log format on Android

below is common log format in android

tv_sec   tv_nsec     priority     pid    tid     tag     messageLen       Message

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)

Log-File locations
There are several directories where logs (including those from crashes) stores and they are not standardized(i.e. some may be ROM-specific). I am putting some common here.

  • /data/anr : Dalvik writes stack traces here on ANR, i.e. “Application Not Responding” aka “Force-Close”
  • /data/dontpanic : contains some crash logs including traces
  • /data/kernelpanics :- Stores “kernel panic” related logs
  • /data/tombstones :- may hold several tombstone_nn files (nn is a number from 0 to 10 and after 10 again repeat it)

‘Log’ command-line tool
To capture Logs from the android devices/emulator Below is some command-line tool. In real-life projects, there are log capture applications/tools used to capture the logs on the user device and shared it back to the Developer/maintainer for analysis.

  • adb logcat (shows all type logs for the current android system
  • adb logcat -v threadtime (it will include date and time)
  • adb logcat -v threadtime > logfile.txt (Store logs in logfile.txt)

Useful filter patterns
You can use the below filter in your adb command to filter logs. You can also use this filter to search your logs file(logs provided by the user device).

  • adb logcat -f <output_file> Save all logs into a file
  • adb logcat “*:E” Get all errors and fatals
  • adb logcat | grep -i “foo.example.” #get all logs related to “foo.example.*” tagname
  • adb logcat “application_or_tag_name:*” “*:S” Get all logs by application name
  • adb logcat -b events “gsm_service_state_change” “*:S” Get all GSM state changes
  • adb logcat -b radio Get all Radio events

Log Analysis
Till now we get all the fundamental exposure of the Android Logging System. Now the time to analyze the logs coming from your application or end-user. Here we can divide log analysis in two-part

  1. Debug Log:- logs file coming during development and testing phase
  2. Production Log:- Logs file coming directly from the end-user.

So guess which one is difficult Production one Right? So what is the best approach to debug and get the desired info from the captured logs? As I discussed above, We can do it by using

So in the last Android log analysis is continuous learning and utilizing your experience process. Personally I analyzed logs via relevant filter and tool with my past experience.

But one thing is good Every android analysis (end-user issue/bug log) gives you new learning and experience. So keep it doing and enjoy your life as a coder and maintainer of android system😎😎😎

Please put your comments in the comment box. It will energize me a lot.

Thanks for the support!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Budhdi Sharma

Budhdi Sharma

328 Followers

A developer is responsible for developing a framework and system applications for devices powered by the Android operating system.