GitHub address: ALog
Functions
- Log can be enabled or disabled
- Configurable output to console (Logcat)
- You can set the Log global Tag
- If the global Tag is empty, the Tag is the current class name
- You can set whether Log displays header information
- The Log header contains the current thread name
- Log header contains the current class and line number and function name, support click jump
- You can set whether Log is written to a file
- You can set the Log file directory
- The Log write file prefix can be set
- Log can be set to display borders
- The Log console filter can be set
- You can set the Log file filter
- You can set the Log stack depth
- Support output of console master string
- Supports multi-parameter output
- Support separate file writing
- Support JSON string output
- Supports output of XML strings
- Support Live Templates
- The JAR package is less than 5Kb
The API -ALog.java-Demo
Init: initializes getConfig: obtainslogSet config. setLogSwitch: SetlogGeneral switch config. setConsoleSwitch: SetlogConsole switch config. setGlobalTag: setlogGlobal Tag config. setLogHeadSwitch: setlogHeader information switch Config. SetLog2FileSwitch: SettingslogFile switch config. setDir: SetlogFile storage directory config.setFilePrefix: setlogFile prefix config.setBorderSwitch: SettingslogBorder switch config. setConsoleFilter: SetlogConsole filter config.setFilefilter: setlogFile filter config.setStackdeep: setlogStack depth V: Verbose d: Debug LOG I: Info log W: Warn log E: Error log A: Assert log File:logTo file json:logJson XML for strings:logXML for stringsCopy the code
How to use
The compile ‘com. Blankj: alog: 1.3.0 or
Usage
Initialize the
Initialize in Application’s onCreate function as follows
// init it in ur application
public void initALog(a) {
ALog.Config config = ALog.init(this)
.setLogSwitch(BuildConfig.DEBUG)// Set the log main switch, including output to console and file, default on
.setConsoleSwitch(BuildConfig.DEBUG)// Set whether to output to the console switch, default on
.setGlobalTag(null)// Set the log global tag, which is null by default
// If the global tag is not empty, we output all the logs of the tag.
If the tag passed in is empty, the class name is displayed, otherwise the tag is displayed
.setLogHeadSwitch(true)// Set the log header switch, default is on
.setLog2FileSwitch(false)// Whether to save files when printing logs is off by default
.setDir("")// If the custom path is empty, it is written to the /cache/log/ directory of the application
.setFilePrefix("")// If the prefix of the file is empty, the default is "alog", that is, the file is written to "alog -mm-dd.txt ".
.setBorderSwitch(true)// Whether to enable the border switch for outputting logs. It is enabled by default
.setConsoleFilter(ALog.V)// Console filter for log, same as logcat filter, default Verbose
.setFileFilter(ALog.V)// Log file filter, same as logcat filter, default Verbose
.setStackDeep(1);// Log stack depth, default is 1
ALog.d(config.toString());
}Copy the code
You can use ALog more easily with the Help of the Live Templates I wrote for you. The demo animations are shown below.
You can download the Live Templates package and go to File→Import Settings in AS.
Tips: If it helpsAndroidUtilCodetheLogUtilsSo you import thisLive Templates, enter ulog will also have a smart template oh.
As for how to write Live Templates, you can actually borrow Live Templates from Android and follow suit.
Legend for default initialization
ALog.d("debug");
ALog.d("customTag", "debug0", "debug1");
ALog.d(longStr);
ALog.file(longStr);
ALog.json(json);
ALog.xml(xml);
Please run demo to see more usage.