Log最佳工具类

使用最好的Log工具类进行项目开发,优秀的工具类:Logger,LogUtils,Timber。


1.工具类初始化

 Logger.initialize(
                Logger.Settings.getInstance()
                        .isShowMethodLink(true)
                        .isShowThreadInfo(false)
                        .setMethodOffset(0)
                        .setLogPriority(BuildConfig.DEBUG ? Log.VERBOSE : Log.ASSERT)

2.打印方法

 private void logTest(){
        //一般打印
        Logger.i("log normal.");
        //多参数打印
        Logger.d("name = %s,age = %s","dandy","26");
        //设置专属TAG打印
        Logger.t("CustomTag").w("log with CustomTag");
        //打印异常信息
        try{
            Class.forName("Dandy");
        }catch (ClassNotFoundException e){
            Logger.e(e,"exception happened!");
        }
        //打印对象
        Logger.object(new User("dandy", "male"));
        //打印list数组
        Logger.object(Arrays.asList("dandy","jack","tony","lili"));
        //打印数组
        Logger.object(new String[]{"Android","ios","wp"});
        //打印double二维数组
        double[][] doubles = {
                {1.2, 1.6, 1.7, 30, 33},
                {1.2, 1.6, 1.7, 30, 33},
                {1.2, 1.6, 1.7, 30, 33},
                {1.2, 1.6, 1.7, 30, 33}
        };
        Logger.object(doubles);
        //打印json格式的字符串
        Logger.json(Dummy.SMALL_SON_WITH_NO_LINE_BREAK);
        String j = "[" + Dummy.JSON_WITH_NO_LINE_BREAK + "," + Dummy.JSON_WITH_LINE_BREAK + "]";
        Logger.json(j);
    }

3.AS配置

dependencies {
    provided "org.projectlombok:lombok:1.12.6"
    compile 'com.jakewharton.timber:timber:4.1.1'
}


4.源代码下载链接 源代码下载链接 源代码下载链接 源代码下载链接 源代码下载链接 源代码下载链接 源代码下载链接



你可能感兴趣的:(android,Logger)