log信息是开发中最最重要的部分,那么如何更好的捕获信息呢?接下来就让我们了解一下强大的log框架–Logger。
添加依赖:
compile 'com.orhanobut:logger:1.15'
Logger
.init("mytag") //LOG TAG默认是PRETTYLOGGER
.methodCount(3) // 决定打印多少行(每一行代表一个方法)默认:2
.hideThreadInfo() // 隐藏线程信息 默认:显示
.logLevel(LogLevel.NONE) // 是否显示Log 默认:LogLevel.FULL(全部显示)
.methodOffset(2) // 默认:0
.logAdapter(new AndroidLogAdapter()); //可以自己构造适配器默认:AndroidLogAdapter
}
默认效果:
Logger.init().logLevel(LogLevel.FULL).methodCount(3);
methodCount(3) ,中间方法区数量变为3,每一行代表一个方法。
2.打印不同level的Log Logger.v(String message); // VERBOSE级别,可添加占位符 Logger.d(Object object); // DEBUG级别,打印对象 Logger.d(String message); // DEBUG级别,可添加占位符 Logger.i(String message); // INFO级别,可添加占位符 Logger.w(String message); // WARN级别,可添加占位符 Logger.e(String message); // ERROR级别,可添加占位符 Logger.e(Throwable throwable, String message); // ERROR级别,可添加占位符 Logger.wtf(String message); // ASSERT级别,可添加占位符 Logger.xml(String xml); Logger.json(String json);
Logger.v("vvvvvvvv");
Logger.d("dddddddd");
Logger.e("eeeeeeee");
Logger.w("wwwwwwww");
Logger.v("vvvvvvvv");
Logger.wtf("wtfwtf");
Logger.json("{\n" +
" \"name\": \"BeJson\",\n" +
" \"url\": \"http://www.bejson.com\",\n" +
" \"page\": 88,\n" +
" \"isNonProfit\": true,\n" +
" \"address\": {\n" +
" \"street\": \"科技园路.\",\n" +
" \"city\": \"江苏苏州\",\n" +
" \"country\": \"中国\"\n" +
" },\n" +
" \"links\": [\n" +
" {\n" +
" \"name\": \"Google\",\n" +
" \"url\": \"http://www.google.com\"\n" +
" },\n" +
" {\n" +
" \"name\": \"Baidu\",\n" +
" \"url\": \"http://www.baidu.com\"\n" +
" },\n" +
" {\n" +
" \"name\": \"SoSo\",\n" +
" \"url\": \"http://www.SoSo.com\"\n" +
" }\n" +
" ]\n" +
"}");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
methodA();
}
void methodA(){
methodB();
}
void methodB(){ Logger.d("methodB","sas","asdasdasd",1);
}
Logger.xml("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<android.support.constraint.ConstraintLayout\n" +
" xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" +
" xmlns:tools=\"http://schemas.android.com/tools\"\n" +
" xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n" +
" android:id=\"@+id/activity_main\"\n" +
" android:layout_width=\"match_parent\"\n" +
" android:layout_height=\"match_parent\"\n" +
" tools:context=\"com.libin.multi.tools.MainActivity\">\n" +
"\n" +
" <TextView\n" +
" android:layout_width=\"wrap_content\"\n" +
" android:layout_height=\"wrap_content\"\n" +
" android:text=\"Hello World!\"\n" +
" app:layout_constraintBottom_toBottomOf=\"@+id/activity_main\"\n" +
" app:layout_constraintLeft_toLeftOf=\"@+id/activity_main\"\n" +
" app:layout_constraintRight_toRightOf=\"@+id/activity_main\"\n" +
" app:layout_constraintTop_toTopOf=\"@+id/activity_main\" />\n" +
" \n" +
" <ImageView\n" +
" android:layout_width=\"wrap_content\"\n" +
" android:layout_height=\"wrap_content\" />\n" +
" \n" +
" <TextView\n" +
" android:layout_width=\"wrap_content\"\n" +
" android:layout_height=\"wrap_content\" />\n" +
"\n" +
"</android.support.constraint.ConstraintLayout>\n");
new Thread(new Runnable() {
@Override
public void run() {
Logger.e("Thread");
}
}).start();