In project development, we encountered a sore point: the project modules are more different log mixed together; when problems arise online, all log information mixed together, positioning difficulties.
To solve this problem, with this tool. This tool has the following functions:
- When developing debug mode is true, printed on the console, and print to a file;
- When debug mode is issued version fase, only print to a file;
- Easy upload log upload log compression support
- Cache files to distinguish between different functional modules support module, print to a different log file;
The first look at the article a friend to me, will face questions from time to time publish manufacturers, Android architecture and other technical knowledge and analytical content, as well as learning source notes PDF + + + Advanced video interview document sharing
The usual learning content on my GitHub: https://github.com/Meng997998/AndroidJX
A, using for example
Log output to the console
Different modules of logs to the corresponding print files
The corresponding log file
Log file path after compression
Second, use
- initialization
- Log fight
- Upload file compression
2.1, initialization
Application of the recommendations put initialization
/**
* 初始化日志
*/
private void initLog() {
// 这里网络模块、UI模块的Debug模式为true
PalUiLog.init(MainApplication.this, true);
PalNetLog.init(MainApplication.this, true);
}
2.2, hit the log
// UI模块日志:打印到控制台;同时打印到文件;
PalUiLog.d(TAG, "---onCreate---");
// 网络模块日志:打印到控制台;同时打印到文件;
PalNetLog.d(TAG, "---onCreate---");
2.3, upload file compression
// 耗时操作,建议异步任务调用该方法
private void zipLogFiles() {
// 压缩App内部存储目录下的日志文件
File file = ZipLogFile.zipLogFiles(MainActivity.this);
// 若压缩成功,返回对应的文件
if (file != null) {
Toast.makeText(MainActivity.this, "日志文件生成成功:" + file.getAbsolutePath(),
Toast.LENGTH_LONG).show();
}
}