Android 常用日志框架
1. Logger「Spring Boot 日志也是Logger,名字一样」
Logger Github 链接 : https://github.com/orhanobut/logger
简单使用:
- 添加依赖:
implementation 'com.orhanobut:logger:2.2.0'
- 初始化日志框架
Logger.addLogAdapter(new AndroidLogAdapter());
- 基本使用
Logger.d("Hello Logger Framework");
//集合「collection」打印
Logger.d(MAP/SET/LIST/ARRAY);
// Json & XML
Logger.json(JSON_CONTENT);
Logger.xml(XML_CONTENT);
- 高级设置「Advanced」
FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
.showThreadInfo(false) // (Optional) Whether to show thread info or not. Default true
.methodCount(0) // (Optional) How many method line to show. Default 2
.methodOffset(7) // (Optional) Hides internal method calls up to offset. Default 5
.logStrategy(customLog) // (Optional) Changes the log strategy to print out. Default LogCat
.tag("My custom tag") // (Optional) Global tag for every log. Default PRETTY_LOGGER
.build();
Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy));
- 日志管控「Logger isEnable」
Log adapter checks whether the log should be printed or not by checking this function. If you want to disable/hide logs for output, override isLoggable method. true will print the log message, false will ignore it.
Logger.addLogAdapter(new AndroidLogAdapter() {
@Override public boolean isLoggable(int priority, String tag) {
return BuildConfig.DEBUG;
}
});
2. LogUtils
LogUtils Github 链接:https://github.com/pengwei1024/LogUtils