Android open source logging tool

In recent project development, I encountered a pain point: there were many project modules and different logs were mixed together; When an online fault occurs, all log information is mixed together, making it difficult to locate the fault. To solve this problem, we have this tool. This tool does the following:

  • Development mode debug is true when printed on the console, while printing to a file;
  • If the debug mode is fase, only files are printed.
  • Easy log upload Compressed log upload is supported
  • The cache file distinction module supports different function modules and prints logs to different files.

I. Examples

  • Logs are output to the console

  • Logs of different modules are printed to corresponding files

  • Logs in corresponding files

  • Path of compressed log files

Two, use mode

  • Initialize the
  • Call log
  • File compression upload

2.1. Initialization

The initialization recommendations are placed in the Application

    /** * Initialization log */
    private void initLog(a) {
		// The Debug mode of the network module and UI module is true
        PalUiLog.init(MainApplication.this.true);
        PalNetLog.init(MainApplication.this.true);
    }
Copy the code

2.2. Log

// UI module log: print to console; Print to file at the same time;
PalUiLog.d(TAG, "---onCreate---");
// Network module log: print to console; Print to file at the same time;
PalNetLog.d(TAG, "---onCreate---");
Copy the code

2.3. File compression and upload

	// It is recommended that asynchronous tasks call this method
    private void zipLogFiles(a) {
		// Compress the log files in the App internal storage directory
        File file = ZipLogFile.zipLogFiles(MainActivity.this);
		// If the compression succeeds, the corresponding file is returned
        if(file ! =null) {
            Toast.makeText(MainActivity.this."Log file generated successfully:"+ file.getAbsolutePath(), Toast.LENGTH_LONG).show(); }}Copy the code

Three, the source address

Github.com/xiaxveliang…

========== THE END ==========