Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 796
not2qubit Avatar asked Jan 06 '17 15:01

not2qubit


People also ask

How does Logcat determine buffer size?

First enable Developer options in Settings. Then navigate to the newly visible Developer options entry, scroll down, and click on logger buffer size . This will display options ranging from off to 16Mb . I have found that when switching to off , logcat will still hold and report a buffer size of 64Kb .

Which Android API class will allow you to output messages to Logcat?

The Log class allows you to create log messages that appear in logcat.

What is verbose in Android Logcat?

Verbose - Show all log messages (the default). Debug - Show debug log messages that are useful during development only, as well as the message levels lower in this list. Info - Show expected log messages for regular usage, as well as the message levels lower in this list.

What is a buffer in Android?

A buffer is a linear, finite sequence of elements of a specific primitive type. Aside from its content, the essential properties of a buffer are its capacity, limit, and position: A buffer's capacity is the number of elements it contains. The capacity of a buffer is never negative and never changes.


1 Answers

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.

Tip: 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 not the main "logcat" debugging log ({@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.

like image 162
not2qubit Avatar answered Oct 10 '22 21:10

not2qubit