按照标准,Android logcat
系统有 4 个不同的环形缓冲区:
main
system
radio
events
# and alias & groups:
all -- all available logs
default -- main
crash -- n/a
但是,在 AOS 6+ 上似乎还有其他缓冲区:
# 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.
...
和安卓logcat.cpp源代码,似乎暗示还有其他的,比如:
security
kernel
通常在 java 应用程序中,将消息放入 main
logcat 的方法是使用:Log.i(TAG, msg)
。
所以问题是: Android 如何确定将哪个缓冲区用于各种 logcat 消息?
(特别感谢对 AOS 源代码的引用。)
那么一个自然而然的后续问题就是,您如何查看或启用其他隐藏缓冲区?
最佳答案
我不喜欢自己回答问题,但我找到了一些答案,还有一些非常好的笔记。
首先,各种日志相关(Java)源文件位于: platform_frameworks_base/core/java/android/util/并在: 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.
相关文件:
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.
日志缓冲区在 Log.java 中标识通过:
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;
在操作系统中,日志记录由属性控制:
setprop log.tag.<YOUR_LOG_TAG> <LEVEL>
并且在文件中 /data/local.prop
通过:
log.tag.<YOUR_LOG_TAG>=<LEVEL>
此外,我还发现了有趣的评论。
MAIN 日志:
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.
EVENT 日志:
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.
关于java - Android 如何确定将哪个缓冲区用于 logcat 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41509161/