Android native system By default, log is not exported to the file, so it is not very convenient for those who can only use the simulator to develop experiments.
Of course, Android does not output log to file by default, also considering the input logs to the file can cause performance problems.
Here's a way to direct logs to a file
To modify the System/core/logcat/logcatd.rc file, add the code at the end of the file:
4096 Ten -F/data/log/android_logs/Applogcat_log class Late_start user root. Group System disabled /dev/cpuset/system-background/tasks
Here, a service named Applogcat is defined, and the corresponding executable file for the service is/system/bin/logcat, and the following/data/log/android_logs/applogcat_log represents the output file path of the log.
Modify the System/core/rootdir/init.rc file to add the following code at the end of the on Post-fs-data phase
Note that this is done in two steps when creating the Data/log/android_logs directory, because the cross-level creation of files (folders) is not supported in the. rc file, so the log directory is created first and then its subdirectory android_logs is created.
Finally, don't forget to use the Start command to start the Applogcat service you just created.
Here, the log service and directory have been created.
At this point, compile, re-phone found only the directory, and no corresponding log file generation.
Use the ADB shell for mobile phones, DMESG check the kernel log, found that SELinux permissions error.
At this point, the correct method should be to add the correct SELinux permissions to the/data/log/android_logs directory, because the SELinux part of the content is not understood, temporarily do not know how to add permissions, so directly from the code to the SELinux off. (This method is not recommended, but it doesn't matter if you play it yourself)
The way to turn off SELinux from the code level is simple, modify the selinux_initialize (bool In_kernel_domain) method in/system/core/init/init.cpp, and the Is_ Enforcing to 0.
Of course, this is not the right way, and so after learning the selinux part of the content, then to update the correct method, first record this method.
Android o version custom log output directory