Sample Header Ad - 728x90

How does android.util.Log internally work?

3 votes
1 answer
103 views
Applications on Android use class android.util.Log for producing logging output with log level, tag etc. We can view the logs using tool logcat. Writing to standard error output also writes to the same log, but with tag System.err. I am wondering how this works internally. Does each application have open some file descriptor to a pipe or socket, which has the “log processing stuff” attached on the other end? When looking to the source code of the android.util.Log class, I see that the messages end up in some native function: /** * Low-level logging call. * @param bufID The buffer ID to receive the message. * @param priority The priority of the message. * @param tag Used to identify the source of a log message. It usually identifies * the class or activity where the log call occurs. * @param msg The message you would like logged. * @return A positive value if the message was loggable (see {@link #isLoggable}). * @hide */ @UnsupportedAppUsage public static native int println_native(int bufID, int priority, String tag, String msg); I also noticed that some of the log can become lost (not flushed) when the process of the app exits directly, using java.lang.System.exit, but the stderr output is not lost. What does this function do? I ask only for educational purposes and I know that the portable way of logging is to use proper Android SDK/NDK functions.
Asked by bindiff (165 rep)
Feb 22, 2025, 03:51 AM
Last activity: Feb 24, 2025, 10:46 AM