Android log management - Log system analysis (2)

 1. Log system overview

        Log.d, Log.v, etc. are often used in App, and ALOGD is used to print logs in the Native layer. For C/C++ applications added by third parties, if you want to use the Android log system, you need to add the liblog library. Here we first study how to classify and store the Logs in the App. Source code analysis takes Android as an example, where liblog and logd have little difference between Android 10 and Android 11 versions. Although logcat has been refactored in C++ on Android 10, the interface of its basic business logic has not changed.

1. Log system framework (Android 9.0)

application layer

        The Android system encapsulates the Java interface of the log system, Log.java, Rlog.java, Slog.java, EventLog.java. Application developers are more familiar with Log.java, and system developers are more familiar with Rlog, Slog, and EventLog interfaces. The functions of these interfaces are similar, and they are all written to logs. The difference is that the log nodes written to logd are different.

  The Java interface is encapsulated in android.jar, which is provided to developers as an SDK, and the system native API is called through the JNI interface in libandroid_runtime.so at runtime.

  For C/C++ developers, you can directly use the ALOGD series APIs provided in log.h to print logs in native programs.

native api

        The core service of the log system is logd, which is a

Guess you like

Origin blog.csdn.net/c19344881x/article/details/131437803