Open-source project log4android Usage Details, log4net open-source
Let's talk about theme directly.
Log4android is an open-source android logging project similar to log4j. The project was adapted based on microlog and added various new definition methods for file output.
Project address: Click Here (https://github.com/lisicnu/Log4Android)
Usage:
0. Import the package.
The project has been released to the maven repository. You can import the package directly. The current version is 1.0.0.
Gradle compilation is as follows:
Compile 'com. github. lisicnu: log4android: 1.0.0'
1. Initialization Method.
LogManager. init (Context), which is located in the assets directory by default to find the microlog. properties file to initialize the log.
LogManager. init (Context, int), open the specified resource file for initialization, and do not specify the SD card file.
LogManager. init (Context, int, boolean) to open the specified file for initialization. You can specify the SD card file.
2. Notes.
LogManger. isDebug this attribute determines whether it is a test mode. If it is a test mode, it is directly output to logcat; otherwise, it is output according to the configuration file.
We recommend that you use. LogManager. isDebug = BuildConfig. DEBUG. The default value is true.
3. usage.
Call LogManager. v (String, Object). and other methods to record logs. Use the same method as android. utl. Log.
4. Configuration File
Example of the complete configuration file:
Microlog. formatter = PatternFormatter
Microlog. formatter. PatternFormatter. pattern = % I % c % d [% P] % m % T
Microlog. appender = FileAppender
Microlog. appender. FileAppender. File = logs
Microlog. appender. FileAppender. Options = % a % f-yyyyMMdd
Microlog. level = DEBUG
Microlog. adddefaloglogger = true
The meaning of PatternFormater is as follows:
% I: // output the clientId set. % c: // output the logger name. % d: // output absolute time % m: // Output Message % P: // output level, such as DEBUG, WARNING, and ERROR. % r: // output the relative time after setting. % t: // output thread name % T: // output throwable details. %: // output %.
Microlog. appender. FileAppender. File this attribute sets the folder name, the default path is the logs folder under the program external SD card data directory.
Microlog. appender. FileAppender. Options sets the attributes of the output file.
% A: // append to the log file. if no, a new file is created. % f: // specify the date used to name the file. The specific date format may be later. such as yyyyMMddHHmmss and yyyMMddHHmm. e.g. % f-yyyyMMddHHmmss % p: // use a fixed file name. When the file size reaches the maximum, a digital index is appended by default. when this attribute is used, microlog. appender. fileAppender. file is recognized as the prefix of the File name. % s: // maximum file size, in MB. 0. If this parameter is not set, files are not separated. for example % s-0.5