Android logger

From eLinux.org
Revision as of 00:01, 12 November 2009 by Tim Bird (Talk | contribs) (Reading)

Jump to: navigation, search

Here is some information on the Android logger:

Overview

General system-wide logging is supported by a kernel device driver call 'logger'. The code for the driver is in 'drivers/android/logger.c'.

The code supports 3 logging buffers, named "main", "events", and "radio", for different types of events.

Driver Features

Log reading and writing is done via normal Linux file reads and writes.

The write path is optimized, so that an open(), write(), close() sequence can occur very quickly, to avoid logging having too much overhead in the system.

Reading

From user-space, a normal 'read' operation is used to read an entry from the log. Each read() returns one log entry, or blocks waiting for the next entry. The device can be opened in non-blocking mode.

At least LOGGER_ENTRY_MAX_LEN (4096) should be used as the amount of data to read from the log on a read request.

Writing

The system performs writes to the log. The driver saves the pid, tgid and timestamp for each log entry. It appears that the level, tag and message are provided by user-space.

ioctls

The following ioctl's are supported, which pretty much do what you would expect:

  • LOGGER_GET_LOG_BUF_SIZE - returns the size of the entire log buffer
  • LOGGER_GET_LOG_LEN - returns the amount of data in the log
  • LOGGER_GET_NEXT_ENTRY_LEN - returns size of next log entry
  • LOGGER_FLUSH_LOG - clears the log of data

Device Nodes

The driver is activated when a user-space program opens a device node with the appropriate major and minor number.

These nodes are located in /dev/log, as shown below:

# ls -l /dev/log
crw-rw--w-    1 0        1007      10,  50 Nov  5 02:00 events
crw-rw--w-    1 0        1007      10,  51 Nov  5 02:00 main
crw-rw--w-    1 0        1007      10,  49 Nov  5 02:00 radio

Logcat command

You can use the 'logcat' command to read the log. This command is located in /system/bin in the local filesystem, or you can access the functionality using the 'adb logcat' command.

Documentation on the use of this command is at: http://developer.android.com/guide/developing/tools/adb.html

Some quick notes:

  • Log messages each have a tag and log level.
    • You can filter the messages by tag and log level, with a different level per tag.
  • You can specify (using a system property) that various programs emit their stdout or stderr to the log.