Timber
来源:互联网 发布:要怎么注销淘宝账号 编辑:程序博客网 时间:2024/06/03 19:04
JakeWharton
Timber
使用方法
编译环境
- 只有一个400多行的类,可以单独把它复制出来放项目里,也可以通过Gradle引用
compile 'com.jakewharton.timber:timber:3.1.0'
API
- 定义一个Log树
public class MyApp extends Application { @Override public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) { Timber.plant(new Timber.DebugTree()); } else { Timber.plant(new CrashReportingTree()); } }}
- 使用,拥有Log的
d
v
i
e
w
方法,但不需要传入tag
Timber.d("Activity Created");
- 定义临时tag
Timber.tag("MainActivity");
原理
Tree
之前的
d
v
i
e
w
方法汇总
/** * {@param priority} Log.ERROR Log.WARN */private void prepareLog(int priority, Throwable t, String message, Object... args) { // 1. 日志级别 if (!isLoggable(priority)) return; // 2. message校验处理 // 3. 获取tag String tag = getTag(); // 4. 输出日志 log(priority, tag, message, t);}// 1. 自定义优先级protected boolean isLoggable(int priority) { return true;}// 3. 获取tag:线程内传参private final ThreadLocal<String> explicitTag = new ThreadLocal<String>();String getTag() { String tag = explicitTag.get(); if (tag != null) { explicitTag.remove(); } return tag;}// 实现真正的日志方法,如默认实现的DebugTree用Log,切割字符串等protected abstract void log(int priority, String tag, String message, Throwable t);
- 森林
private static final List<Tree> FOREST = new CopyOnWriteArrayList<Tree>();public static void plant(Tree tree) {...}public static void uprootAll() { FOREST.remove(tree)}
Hugo
有时候需要打印方法的传参和返回值,甚至方法的执行时间,一个个拼接很麻烦,此时只要在方法上加上@DebugLog 就可以自动实现
其他
WebViewFragment
WebView使用的正确姿势PhoneNumberUtils
和PhoneNumberFormattingTextWatcher
Android 不为人知的API
0 0
- Timber
- Timber使用
- Timber的使用与源码分析
- Timber 经典的android Log封装库
- JakeWharton的timber自动生成Tag原理
- Android调试自测工具 (Hugo、Timber、Scalpel)
- [codeplus 11月月赛]T2 timber
- 第三方框架Timber使用简单记录
- HPL formica plywood,BS1088 marine plywood,H timber beam
- HPL formica plywood,BS1088 marine plywood,H timber beam
- HPL formica plywood,BS1088 marine plywood,H timber beam
- Android 调试 自测工具01 (Hugo 、Timber 、Scalpel )
- Android 调试 自测工具01 (Hugo 、Timber 、Scalpel )
- Android 调试 自测工具01 (Hugo 、Timber 、Scalpel )
- Timber(对Log类封装的一个工具)
- 开发工具——日志Timber的使用
- Dlubal RX-TIMBER 2.09.01 Win64 1CD
- 工具类——使用Timber自定义日志并保存文件查看
- 断点续传---多线程下载进阶(三)
- iOS系统和XCode各版本发布日期
- HTML5 drag的使用案例 --- 类似于图片墙
- FatMouse's Speed
- js: 实现Select的option上下移动
- Timber
- 黑马程序员03数组排序与二分法查找
- MyBatis拦截器实现mysql与oracle共用分页
- Android内存分析工具(四):adb命令
- 【面试题之算法部分】最长回文子串
- ural 1272. Non-Yekaterinburg Subway
- Spring拦截器中通过request获取到该请求对应Controller中的method对象
- WebService为什么不如RESTful API流行
- MySQL数据库默认编码查看/修改