简体   繁体   中英

How does Android determine which buffer to use for logcat messages?

By standard, the Android logcat system have 4 different ring buffers:

main
system
radio
events

# and alias & groups:
all      -- all available logs
default  -- main
crash    -- n/a

However, on AOS 6+ there seem to be other buffers as well:

# logcat --help
...
  -b <buffer>     Request alternate ring buffer, 'main', 'system', 'radio',
                  'events', 'crash' or 'all'. Multiple -b parameters are
                  allowed and results are interleaved. The default is
                  -b main -b system -b crash.
...

and the android logcat.cpp source code, seem to imply there are still other ones, such as:

security 
kernel

Normally in java apps, the way to put a message in main logcat is by using: Log.i(TAG, msg) .

So the question is: How does Android determine which buffer to use for the various logcat messages?

(Specific references to the AOS source code would be especially appreciated.)

Then a natural follow up question would be, how can you see or enable the other hidden buffers?

I don't like to answer my own questions, but I've found a few answers, and also some very good notes.

First, the various log related (Java) source files are located in: platform_frameworks_base/core/java/android/util/ and in: platform_frameworks_base/telephony/java/android/telephony/ .

EventLog.java   # EVENT Log:  These diagnostic events are for system integrators, not application authors.
Log.java        # MAIN Log:   Where user app logcat goes from:  Log.v() Log.d() Log.i() Log.w() and Log.e()
Slog.java       # SYSTEM Log: Primarily for use by coding running within the system process.
Rlog.java       # RADIO Log:  All radio, wifi, bluetooth etc. related logs. Also scrubs personal info from appearing in logs. 

with the related files:

EventLogTags.java       # Deprecated! (Use EventLog)
LocalLog.java           # log(), dump(), reverseDump(), ReadOnlyLocalLog()
LogPrinter.java         #  decides what buffer to print to: LOG_ID_<buffer_name>
LogWriter.java          #  decides priority and TAG
TimingLogger.java       # A utility class to help log timings splits throughout a method call.

The log buffers are identified in Log.java by:

public static final int LOG_ID_MAIN = 0;
public static final int LOG_ID_RADIO = 1;
public static final int LOG_ID_EVENTS = 2;
public static final int LOG_ID_SYSTEM = 3;
public static final int LOG_ID_CRASH = 4;

In the OS, the logging is governed by the properties:

setprop log.tag.<YOUR_LOG_TAG> <LEVEL>

and in the file /data/local.prop by:

log.tag.<YOUR_LOG_TAG>=<LEVEL>

Furthermore, I found the interesting comments.

The MAIN log:

The order in terms of verbosity, from least to most is ERROR, WARN, INFO, DEBUG, VERBOSE. Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.

Don't forget that when you make a call like 当你拨打电话时不要忘记

 Log.v(TAG, "index=" + i);  

that when you're building the string to pass into Log.d, the compiler uses a StringBuilder and at least three allocations occur: the StringBuilder itself, the buffer, and the String object. Realistically, there is also another buffer allocation and copy, and even more pressure on the gc. That means that if your log message is filtered out, you might be doing significant work and incurring significant overhead.

The EVENT log:

Access to the system diagnostic event record. System diagnostic events are used to record certain system-level events (such as garbage collection, activity manager state, system watchdogs, and other low level activity), which may be automatically collected and analyzed during system development.

This is the main "logcat" debugging log ({@link android.util.Log})! 主要的“logcat”调试日志({@link android.util.Log})! These diagnostic events are for system integrators, not application authors.

Events use integer tag codes corresponding to /system/etc/event-log-tags. They carry a payload of one or more int, long, or String values. The event-log-tags file defines the payload contents for each type code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM