特来为各位推广Android日志工具,漂亮强大简单到你离不开它!
2017-03-31 本文已影响259人
ayvytr
(抱歉,发生了图破了的情况)
Logger(去点个Star吧!)
Simple, pretty and powerful logger for android(简单,漂亮,强大的Android日志工具)
提供了:
- 线程信息
- 类信息
- 方法名
- Json字符串格式化打印
- 遇到"\n"字符换行显示
- 清除输出
- 跳转到源代码
- 你想要的各种输出效果
JCenter
compile 'com.ayvytr:logger:1.0.0'
JitPack
Step 1. Add the JitPack repository to your build file
Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
Step 2. Add the dependency
dependencies {
compile 'com.github.Ayvytr:Logger:1.1.0'
}
JCenter-1.0.0和 JitPack-1.1.0是同一个版本。不同的原因是JitPack小状况
使用
多参数使用
L.e("message", "arg1", 2, "arg3");

Array, Map, Set 和 List 输出
L.i("Array", 1, 2, "aa", "bb");
L.i("List", list);
L.v("Map", map);
L.e("Set", set);
L.w("Collection", list, map, set);

第一个参数什么类型都可以
L.i(1, 2, "aa", "bb");
L.i(list);
L.v(map);
L.e(set);
L.w(list, map, set);
Log based
L.t("mytag").d("hello");

设置Tag
随时更改
L.t("MyTag").e(1);
直接设置
L.getSettings().tag("MyTag");
更改输出的方法数量 (聪明的你是不是发现了什么?)
L.getSettings().methodCount(10);
L.t(1).d("hello");

更改方法栈偏移(方法调用信息将会前移数量,和前边一张图片比较一下)
L.getSettings().methodOffset(10);

隐藏线程信息
L.getSettings().hideThreadInfo();

不想显示方法调用信息
L.getSettings().methodCount(0);

打印Json
L.json(YOUR_JSON_DATA);

直接打印异常
L.e(exception,"message");
设置(入口:L.getSettings())
L
.getSettings() // 获取Settings
.tag(YOUR_TAG) // 默认tag: PRETTYLOGGER
.methodCount(3) // 默认为 2
.hideThreadInfo() // 隐藏线程信息(默认显示)
.logLevel(LogLevel.NONE) // 默认 LogLevel.FULL
.methodOffset(2) // default 0
.logAdapter(new AndroidLogAdapter()); //default AndroidLogAdapter
}
你的无(biàn)理(tài)要求我都能满足
默认的样子
L.d("hello");
L.d("hello", "world", 5);

L.d("hello");
L.e("hello");
L.w("hello");
L.v("hello");
L.wtf("hello");
L.json(JSON_CONTENT);
L.xml(XML_CONTENT);
L.log(DEBUG, "tag", "message", throwable);
我要每个日志都单独被框住
L.getSettings().showBottomBorder(true);
L.d("hello");
L.d("hello", "world", 5);

我要每条日志连起来(默认)

我只想要我日志内容,不要框子
L.getSettings().justShowMessage(true);
L.d("hello");
L.d("hello", "world", 5);

我只想用,参数都不想填一个(我会帮你打印类和方法名)
L.getSettings().justShowMessage(true);
L.d();
L.w();

我要屏蔽日志(试试看能不能打印出来?)
L.getSettings().logLevel(LogLevel.NONE);
替代我的LogAdapter
class CustomLogAdapter Implement LogAdapter {}
settings.logAdapter(new CustomLogAdapter())
Notes
- 使用日志筛选,格式更整齐

- 确认关掉日志换行选项

- Release使用LogLevel.NONE不输出任何日志