Logger
Logger是一款强大的开源日志库,可以实现清晰的打印效果
![这里写图片描述](https://github.com/orhanobut/logger/raw/master/art/logger_output.png)
引包
compile 'com.orhanobut:logger:2.1.1'
初始化
FormatStrategy formatStrategy = PrettyFormatStrategy.newBuilder()
.showThreadInfo(true) // 是否打印线程号,默认true
.methodCount(5) // 展示几个方法数,默认2
.methodOffset(7) // (Optional) Hides internal method calls up to offset. Default 5
// .logStrategy(customLog) //是否更换打印输出,默认为logcat
.tag("meee") // 全局的tag
.build()
Logger.addLogAdapter(new AndroidLogAdapter(formatStrategy))
普通的打印
Logger.d("hello")
Logger.e("hello")
Logger.w("hello")
Logger.v("hello")
Logger.wtf("hello")
支持打印数组和集合(仅支持Debug模式)
HashMap<String, String> map = new HashMap<>();
map.put("key1","value1");
map.put("key2","value2");
map.put("key3","value3");
ArrayList<String> list = new ArrayList<>();
list.add("list1");
list.add("list2");
list.add("list3");
String[] strs={"strs1","strs2","strs3"};
Logger.d(list);
Logger.d(map);
Logger.d(strs);
一次性的tag
Logger.t("tag_string");
支持xml和json
JSONObject json = createJson();
Logger.d(json.toString());
Logger.json(json.toString());
Logger.xml("xmlString");
private JSONObject createJson() {
try {
JSONObject person = new JSONObject();
person.put("phone", "12315");
JSONObject address = new JSONObject();
address.put("country", "china");
address.put("province", "fujian");
address.put("city", "xiamen");
person.put("address", address);
person.put("married", true);
return person;
} catch (JSONException e) {
Logger.e(e, "create json error occured");
}
return null;
}
10-16 14:25:07.197 3743-3743/? D/meee-tag_string: │ {"phone":"12315","address":{"country":"china","province":"fujian","city":"xiamen"},"married":true}
10-16 14:25:07.197 3743-3743/? D/meee: │ {
10-16 14:25:07.197 3743-3743/? D/meee: │ "phone": "12315",
10-16 14:25:07.197 3743-3743/? D/meee: │ "address": {
10-16 14:25:07.197 3743-3743/? D/meee: │ "country": "china",
10-16 14:25:07.197 3743-3743/? D/meee: │ "province": "fujian",
10-16 14:25:07.197 3743-3743/? D/meee: │ "city": "xiamen"
10-16 14:25:07.197 3743-3743/? D/meee: │ },
10-16 14:25:07.197 3743-3743/? D/meee: │ "married": true
10-16 14:25:07.197 3743-3743/? D/meee: │ }
10-16 14:25:07.197 3743-3743/? D/meee: └────────────────────────────────────────────────────────────────────────────────────────────────────────────────