Difference between revisions of "Android logger"

From eLinux.org
Jump to: navigation, search
(Overview: Add more information)
(4 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
The code for the driver is in 'drivers/android/logger.c'.
 
The code for the driver is in 'drivers/android/logger.c'.
  
The code supports 3 logging buffers, named "main", "events", and "radio", for different
+
The code supports 4 logging buffers, named "main", "events", "radio", and "system" for different
 
types of events.
 
types of events.
  
=== Driver Features ===
+
== Driver Features ==
 
Log reading and writing is done via normal Linux file reads and writes.
 
Log reading and writing is done via normal Linux file reads and writes.
  
Line 14: Line 14:
 
very quickly, to avoid logging having too much overhead in the system.
 
very quickly, to avoid logging having too much overhead in the system.
  
==== Reading ====
+
=== Reading ===
From user-space, use a normal 'read' operation to read an entry from
+
From user-space, a normal 'read' operation is used to read an entry from
the log.
+
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
 
At least LOGGER_ENTRY_MAX_LEN (4096) should be used as the amount of data to read from the log on a read
 
request.
 
request.
  
==== Writing ====
+
=== Writing ===
 
The system performs writes to the log.  The driver saves the pid, tgid and timestamp for each log entry.
 
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.
 
It appears that the level, tag and message are provided by user-space.
  
==== ioctls ====
+
=== ioctls ===
  
 
The following ioctl's are supported, which pretty much do what you would expect:
 
The following ioctl's are supported, which pretty much do what you would expect:
Line 43: Line 44:
 
  crw-rw--w-    1 0        1007      10,  49 Nov  5 02:00 radio
 
  crw-rw--w-    1 0        1007      10,  49 Nov  5 02:00 radio
  
== Logcat command ==
+
/dev/log/system was added in Feb, 2010
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:
+
== Android Logging System ==
http://developer.android.com/guide/developing/tools/adb.html
+
See [[Android Logging System]] for information about the complete android logging system, including tools which access this driver.
  
Some quick notes:
+
[[Category:Android]]
* 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.
+

Revision as of 00:12, 15 January 2011

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 4 logging buffers, named "main", "events", "radio", and "system" 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

/dev/log/system was added in Feb, 2010

Android Logging System

See Android Logging System for information about the complete android logging system, including tools which access this driver.