1.前言

在所有开发中,日志输出极为重要。Android 为我们提供简单便捷的Log 工具类,在项目开发中,无论代码中还是控制台,Log 处处可见,难免造成代码混乱,Log 究竟从哪里打印的。更有些设备比如电视盒子,车载系统,贩卖机机台,adb 权限不开放,但boss 却让你为其适配,开发时,出现问题时,只能眼巴巴看着代码!!!

Logcat 能干什么?

  1. 全局控制Log 是否输出, 显示那个日志等级输出
  2. 能将Log 信息保存到文件中查看
  3. 打印行号、函数调用、Json解析、点击跳转、多标签Tab 等功能
  4. 没了,只不过是Log 包装的工具类

Logcat

Github 点我


这是一个Android 上 效率极高的 Log 工具,主要功能为控制不同级别的Log输出,Log信息保存到文件、打印行号、函数调用、Json解析、点击跳转、多标签Tag 支持无限长字符串打印,无Logcat4000字符限制等功能

打印行号、函数调用、Json解析、点击跳转 参照KLog of ZhaoKaiQiang.


Gradle

dependencies {    compile 'com.lazy.logging:library:1.3.0'}

1.开始使用 Logcat

你只需要在 Application 里面调用Logcat.initialize一次即可完成初始化

//初始化LogcatLogcat.initialize(this);

配置更多信息

Builder builder = Logcat.newBuilder();//设置Log 保存的文件夹builder.logSavePath(StorageUtils.getDiskCacheDir(this, "log"));//设置输出日志等级if (BuildConfig.DEBUG) {  builder.logCatLogLevel(Logcat.SHOW_ALL_LOG);} else {  builder.logCatLogLevel(Logcat.SHOW_INFO_LOG | Logcat.SHOW_WARN_LOG | Logcat.SHOW_ERROR_LOG);}//设置输出文件日志等级builder.fileLogLevel(Logcat.NOT_SHOW_LOG);Logcat.initialize(this, builder.build());

2.示例

//控制台Logcat.v("The is verbose log");Logcat.d("The is debug log");Logcat.i("The is info log");Logcat.w("The is warn log");Logcat.e("The is error log");

3.LogTransaction 为Logcat 提供灵活的链式调用api

msg(@NonNull final Object msg);// 打印 msgmsgs(@NonNull final Object... msg);// n ... msgtag(@NonNull final String tag);// 打印 tagtags(@NonNull final String... tags); //n ... tagfile(); // log默认输出到文件file(@NonNull final String fileName); //指定文件名ln(); //换行format(@NonNull final String format, Object... args); //格式化out(); //输出log

4.Logcat log 文件

--默认log文件夹 sdcard/Android/data/you.pakeage/cache/logs 下//文件log 格式V/Logcat->newTag 2017-04-15_21:10:17fileName:MainActivity.javaclassName:com.lazy.logging.MainActivitymethodName:OnCreatelineNumber:78output file msg result =  4 

5.Sample Usage

License

Copyright  2016 LazyLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at   http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

About me
Email: 13532605287@163.com

更多相关文章

  1. 深入浅出 Android(安卓)Service (5)
  2. Android——AsyncTask
  3. android 5.0 创建多用户 双开多开应用(1)
  4. Android(安卓)P版本(9.0) 新功能介绍和兼容性处理
  5. Android(安卓)NDK开发之Jni调用Java对象
  6. android 蓝牙小总结
  7. Android(安卓)HAL层/native C程序打印栈信息方法
  8. Android中Dialog对话框的调用及监听
  9. Android(安卓)编程技巧之 ----- 自定义 View 踩坑总结

随机推荐

  1. Android Studio(六):Android Studio添加注
  2. ADT对应的.android中找不到adb_usb.ini
  3. android:installLocation 用法科普
  4. Android(安卓)APP首次登录和之后自动登录
  5. Android studio启动后无法更新
  6. 第1个Android应用程序 Android制作简单单
  7. Android中的visibility属性的区别
  8. android开发 加载so库的解析和出现的各种
  9. android 用代码画虚线边框背景
  10. android-详解Android中的屏幕方向