Android 开源框架Logger的使用
来源:互联网 发布:淘宝设计论坛 编辑:程序博客网 时间:2024/06/06 19:25
日志开源框架的话,Logger不可不谈。简单的调用就能得到清晰的Log输出,对于日后调试和修改bug都是不错的选择。
◆Logger的官方地址
https://github.com/orhanobut/logger
◆Logger的使用
Eclipse:直接下载源码导入项目中
Android studio:compile 'com.orhanobut:logger:1.15'
◆使用方法
import com.orhanobut.Logger.LogLevel; import com.orhanobut.Logger.Logger; import com.orhanobut.Logger.Settings; public class MainActivity extends Activity { ...protected void onCreate(Bundle savedInstanceState) {...JSONObject json = createJson(); Settings settings = Logger.init("EllisonLog"); // 配置tagsettings.methodCount(3); // 配置Log中调用堆栈的函数行数// settings.hideThreadInfo(); // 隐藏Log中的线程信息settings.methodOffset(0); // 设置调用堆栈的函数偏移值,0的话则从打印该Log的函数开始输出堆栈信息settings.logLevel(LogLevel.FULL); // 设置Log的是否输出,LogLevel.NONE即无Log输出Logger.i("activity created"); // 打印infoLogger.e(new Exception("test exception"), "error occured"); // 打印exceptionLogger.json(json.toString()); // 打印json }private JSONObject createJson() {try { JSONObject person = new JSONObject(); person.put("phone", "12315"); JSONObject address = new JSONObject(); address.put("country", "china"); address.put("province", "jiangsu"); address.put("city", "nanjing"); person.put("address", address); person.put("married", true); return person;} catch (JSONException e) {Logger.e(e, "create json error occured");}return null;} }
◆ログ输出
●info07-14 17:58:38.246: I/EllisonLog(26917): ╔════════════════════════════════════════════════════════════════════════════════════════07-14 17:58:38.247: I/EllisonLog(26917): ║ Thread: main07-14 17:58:38.247: I/EllisonLog(26917): ╟───────────────────────────────────────────────07-14 17:58:38.247: I/EllisonLog(26917): ║ Instrumentation.callActivityOnCreate (Instrumentation.java:1111)07-14 17:58:38.247: I/EllisonLog(26917): ║ Activity.performCreate (Activity.java:6315)07-14 17:58:38.248: I/EllisonLog(26917): ║ MainActivity.onCreate (MainActivity.java:38)07-14 17:58:38.248: I/EllisonLog(26917): ╟───────────────────────────────────────────────07-14 17:58:38.248: I/EllisonLog(26917): ║ activity created07-14 17:58:38.248: I/EllisonLog(26917): ╚════════════════════════════════════════════════════════════════════════════════════════●exception07-14 17:58:38.249: E/EllisonLog(26917): ╔════════════════════════════════════════════════════════════════════════════════════════07-14 17:58:38.249: E/EllisonLog(26917): ║ Thread: main07-14 17:58:38.249: E/EllisonLog(26917): ╟───────────────────────────────────────────────07-14 17:58:38.249: E/EllisonLog(26917): ║ Instrumentation.callActivityOnCreate (Instrumentation.java:1111)07-14 17:58:38.249: E/EllisonLog(26917): ║ Activity.performCreate (Activity.java:6315)07-14 17:58:38.250: E/EllisonLog(26917): ║ MainActivity.onCreate (MainActivity.java:39)07-14 17:58:38.250: E/EllisonLog(26917): ╟───────────────────────────────────────────────07-14 17:58:38.250: E/EllisonLog(26917): ║ error occured : java.lang.Exception: test exception07-14 17:58:38.250: E/EllisonLog(26917): ║ at com.example.timeapidemo.MainActivity.onCreate(MainActivity.java:39)07-14 17:58:38.250: E/EllisonLog(26917): ║ at android.app.Activity.performCreate(Activity.java:6315)07-14 17:58:38.250: E/EllisonLog(26917): ║ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)07-14 17:58:38.250: E/EllisonLog(26917): ║ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2431)07-14 17:58:38.250: E/EllisonLog(26917): ║ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2541)07-14 17:58:38.250: E/EllisonLog(26917): ║ at android.app.ActivityThread.access$900(ActivityThread.java:182)07-14 17:58:38.250: E/EllisonLog(26917): ║ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1406)07-14 17:58:38.250: E/EllisonLog(26917): ║ at android.os.Handler.dispatchMessage(Handler.java:102)07-14 17:58:38.250: E/EllisonLog(26917): ║ at android.os.Looper.loop(Looper.java:148)07-14 17:58:38.250: E/EllisonLog(26917): ║ at android.app.ActivityThread.main(ActivityThread.java:5613)07-14 17:58:38.250: E/EllisonLog(26917): ║ at java.lang.reflect.Method.invoke(Native Method)07-14 17:58:38.250: E/EllisonLog(26917): ║ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)07-14 17:58:38.251: E/EllisonLog(26917): ║ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)07-14 17:58:38.251: E/EllisonLog(26917): ╚════════════════════════════════════════════════════════════════════════════════════════●json07-14 17:58:38.251: D/EllisonLog(26917): ╔════════════════════════════════════════════════════════════════════════════════════════07-14 17:58:38.252: D/EllisonLog(26917): ║ Thread: main07-14 17:58:38.252: D/EllisonLog(26917): ╟───────────────────────────────────────────────07-14 17:58:38.252: D/EllisonLog(26917): ║ Instrumentation.callActivityOnCreate (Instrumentation.java:1111)07-14 17:58:38.252: D/EllisonLog(26917): ║ Activity.performCreate (Activity.java:6315)07-14 17:58:38.252: D/EllisonLog(26917): ║ MainActivity.onCreate (MainActivity.java:40)07-14 17:58:38.252: D/EllisonLog(26917): ╟───────────────────────────────────────────────07-14 17:58:38.252: D/EllisonLog(26917): ║ {07-14 17:58:38.252: D/EllisonLog(26917): ║ "phone": "12315",07-14 17:58:38.252: D/EllisonLog(26917): ║ "address": {07-14 17:58:38.252: D/EllisonLog(26917): ║ "country": "china",07-14 17:58:38.252: D/EllisonLog(26917): ║ "province": "jiangsu",07-14 17:58:38.252: D/EllisonLog(26917): ║ "city": "nanjing"07-14 17:58:38.252: D/EllisonLog(26917): ║ },07-14 17:58:38.253: D/EllisonLog(26917): ║ "married": true07-14 17:58:38.253: D/EllisonLog(26917): ║ }07-14 17:58:38.253: D/EllisonLog(26917): ╚════════════════════════════════════════════════════════════════════════════════════════
Logger还可以打印xml,日后追加。
3 0
- Android 开源框架Logger的使用
- iOS的开源Logger框架使用
- Android Logger框架简单使用
- Android 开源日志库Logger的简单使用
- Android开源日志库Logger的使用
- Android强大log框架Logger使用详解
- Android强大log框架Logger使用详解
- Android Logger开源库的使用
- 超好用的Android日志打印框架--Logger
- 超好用的Android日志打印框架--Logger
- 超好用的Android日志打印框架--Logger
- 开源日志库Logger的使用
- 开源工具库Logger的使用
- 开源日志库Logger的使用
- android日志框架Logger的详细使用(目前最新版2.1.1)
- Android 开源日志库 Logger 使用教程
- Android 开源日志库 Logger 使用教程
- Android 开源日志库 Logger 使用教程
- android入门:zxing学习笔记(三)
- 计算广告的历史、现状及未来
- [Windows][VC]开机自动启动程序的几种方法
- 人月神话读书笔记(4)----贵族专制、民主政治和系统设计
- Tesseract-OCR3.0语言库训练步骤
- Android 开源框架Logger的使用
- CnCrypt代码 之 获取程序自身版本号
- java 位运算常用技巧
- spring-boot 集成jpa 持久层
- 51nod1623完美消除 【数位dp】
- C++实现RTMP协议发送H.264编码及AAC编码的音视频
- 这么久总算过了删数问题~~
- HashMap实现原理分析
- 改变webview字体大小