Here is my understanding about logcat, maybe there are some errors, welcome any comments:
About the log file in the phone: From frameworks/base/core/jni/android_util_Log.cpp we will see that all entries will be written to the /dev/log/ folder on your devices by default. main will be written to /dev/log/main radio will be written to /dev/log/radio ... because all the input / output files of the operator system. Thus, when you restart the phone, it will be cleared. And the size of these files has some limitation, if the size reaches the limit, the old log will be redefined.
About Logcat: Logcat is a tool for reading or retrieving log files. It is installed in the system / bin / folder on the phone. I do not read every logcat.cpp code; but I can say that the logcat application will read the log file in system / logcat / main by default and display them on the screen or file based on the parameters you use.
About how the log is created: If you see the source code for android.util.log , you can find all log.d / log.e to use the JNI method to write log to log files as above.
public static native int println_native(int bufID,int priority, String tag, String msg);
Here you can find the JNI method here . If this interests you, you can read the source code to find out what it does there.
Save the log code in the desired file: Based on the I / O of the log, the developer can write an application to save the log to a file on the SD card in the phone so that we can store more logs or a larger log file. The easiest way is to use Runtime.exec() to execute the logcat application: You can follow the completed BOOT receiver to run the logcat command to read the entire logcat log into its own files.
For example:
String cmd = "logcat -v time -f yourown.file" Process process = Runtime.getRuntime().exec(cmd);
buptcoder
source share