博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android Logging System
阅读量:2342 次
发布时间:2019-05-10

本文共 5650 字,大约阅读时间需要 18 分钟。

This article describes the Android logging system

Contents

[]

Overview

The Android system has a logging facility that allows systemwide logging of information, from applications and system components.This is separate from the Linux kernel's own logging system, which is accessed using 'dmesg' or '/proc/kmsg'. However, the logging system does store messages in kernel buffers.

image by Tetsuyuki Kobabayshi, of Kyoto Microcomputer Co.

The logging system consists of:

  • a kernel driver and kernel buffers for storing log messages
  • C, C++ and Java classes for making log entries and for accessing the log messages
  • a standalone program for viewing log messages (logcat)
  • ability to view and filter the log messages from the host machine (via eclipse or ddms)

There are four different log buffers in the Linux kernel, which provide logging for different parts of the system.Access to the different buffers is via device nodes in the file system, in /dev/log.

The four log buffers are:

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

Up until 2010, only the first three logs existed. The system log was created to keep system messages in a separatebuffer (outside of '/dev/log/main') so that a single verbose application couldn't overrun system messagesand cause them to be lost.

Each message in the log consists of a tag indicating the part of the system or application that the message came from,a timestamp, the message log level (orpriority of the event represented by the message) and the log message itself.

All of the log buffers except for 'event' use free-form text messages. The 'event' buffer is a 'binary' buffer,where the event messages (and event parameters) are stored in binary form. This form is more compact, but requiresextra processing when the event is read from the buffer, as well as a message lookup database, to decode the event strings.

The logging system automatically routes messages with specific tags into the radio buffer. Other messages are placedinto their respective buffers when the the log class or library for that buffer is used.

Kernel driver

The kernel driver for logging is called the 'logger'. See

System and Application logging

Application log

An Android application includes the , and uses methods of this class 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).

Event log

Event logs messages are created using , which create 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.

System log

Many classes in the Android framework utilize the system log to keep their messages separate from (possibly noisy) application log messages. These programs use the android.util.Slog class, with its associated messages.

In all cases, eventually a formatted message is delivered through the C/C++ library down to the kernel driver, which stores the message in the appropriate buffer.

'log' command line tool

There is a 'log' command line tool that can be used to create log entries fromany program. This is built into the 'toolbox' multi-function program.

The usage for this is:

USAGE: log [-p priorityChar] [-t tag] message       priorityChar should be one of:               v,d,i,w,e

Capturing stdout with logwrapper

It is sometimes useful to capture stdout from native applications into the log. There is a utility called'logwrapper' which can be used to run a program, and redirect it's stdout into log messages.

The logwrapper usage is:

Usage: logwrapper [-x] BINARY [ARGS ...]Forks and executes BINARY ARGS, redirecting stdout and stderr tothe Android logging system. Tag is set to BINARY, priority isalways LOG_INFO.-x: Causes logwrapper to SIGSEGV when BINARY terminates    fault address is set to the status of wait()

Source for logwrapper is at: system/core/logwrapper/logwrapper.c

Logcat command

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

Documentation on the use of this command is at:

Some quick notes:

  • Log messages each have a tag and priority.
    • 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.

Trick to couple Android logging to Linux kernel logging

Note that the android logging system is completely separate fromthe Linux kernel log system (which uses printk inside the kernelto save messages and dmesg to extract them). You can write tothe kernel log from user space by writing to /dev/kmsg.

I've seen a reference to couple the two together, to redirectandroid messages into the kernel log buffer, using the 'logcat'program launched from init, like below:

service logcat /system/bin/logcat -f /dev/kmsg       oneshot

(See )

I'm not sure why you'd want to do this (maybe to put all messages into a single stream? With the same timestamp, if kernel message timestamping is on?)

Resources

  • - has 'adb logcat' usage information
  • Presentation by Tetsuyuki Kobayashi, September, 2010 at CELF's

转载地址:http://uhfvb.baihongyu.com/

你可能感兴趣的文章
word设置标题
查看>>
git之HEAD
查看>>
基于2.6内核的Init_task进程之一
查看>>
C代码插入汇编
查看>>
C++基础知识-之强指针(韦东山视频学习)
查看>>
C++之Android弱指针
查看>>
C++基础知识之vector和[=] [&] [=,&]拷贝
查看>>
C语言常见错误
查看>>
Init中的next_token()函数
查看>>
STL之MAP和Vector
查看>>
智能指针 unique_ptr
查看>>
Init.rc配置文件Action字段解析
查看>>
uml问题解决
查看>>
cpu结构框图
查看>>
mmap内存映射和shmget共享内存
查看>>
c中int和long类型
查看>>
二维字符数组与字符串数组
查看>>
c中指针赋值为0
查看>>
c中求二维数组的行数和列数
查看>>
三目运算符跟赋值运算符的计算顺序
查看>>