Android log 管理工具
生活随笔
收集整理的這篇文章主要介紹了
Android log 管理工具
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1、logger
? ? ?項(xiàng)目地址:?https://github.com/orhanobut/logger
2、KLog
? ? 項(xiàng)目地址:https://github.com/ZhaoKaiQiang/KLog
? ? ?博客介紹:?http://kaizige.vip/2016/06/13/klog/
3、自定義日志?
? ? ?上面兩個(gè)日志框架使用起來很簡單,功能很強(qiáng)大,但是有時(shí)我們不需要那么強(qiáng)大的功能,或者為了盡可能精簡代碼,壓縮apk包的大小。那就使用下面一個(gè)自定義的日志管理類,只有一個(gè)類,小而巧。
package www.yiba.com.wifisdk.utils;import android.util.Log;/*** 日志工具類 使打印日志變得簡單 自動(dòng)識(shí)別調(diào)用日志函數(shù)的類名 方法名 與位置 不需要繁瑣的TAG 可以方便的 設(shè)置debug模式 發(fā)布時(shí)候* 可以直接修改debug為false 就不會(huì)輸出日志了*/ public class LogUtil {/*** true:打開log false:關(guān)閉所有的日志*/public static boolean OPEN_LOG = true;/*** true : 打開debug 日志 false:關(guān)閉debug日志*/public static boolean DEBUG = true;/*** TAG 名稱*/private static String tag = "yiba_sdk";private String mClassName;private static LogUtil log;private static final String USER_NAME = "@tool@";private LogUtil(String name) {mClassName = name;}/*** Get The Current Function Name** @return Name*/private String getFunctionName() {StackTraceElement[] sts = Thread.currentThread().getStackTrace();if (sts == null) {return null;}for (StackTraceElement st : sts) {if (st.isNativeMethod()) {continue;}if (st.getClassName().equals(Thread.class.getName())) {continue;}if (st.getClassName().equals(this.getClass().getName())) {continue;}return mClassName + "[ " + Thread.currentThread().getName() + ": "+ st.getFileName() + ":" + st.getLineNumber() + " "+ st.getMethodName() + " ]";}return null;}public static void i(Object str) {print(Log.INFO, str);}public static void d(Object str) {print(Log.DEBUG, str);}public static void v(Object str) {print(Log.VERBOSE, str);}public static void w(Object str) {print(Log.WARN, str);}public static void e(Object str) {print(Log.ERROR, str);}/*** 用于區(qū)分不同接口數(shù)據(jù) 打印傳入?yún)?shù)** @param index* @param str*/private static void print(int index, Object str) {if (!OPEN_LOG) {return;}if (log == null) {log = new LogUtil(USER_NAME);}String name = log.getFunctionName();if (name != null) {str = name + " - " + str;}// Close the debug log When DEBUG is falseif (!DEBUG) {if (index <= Log.DEBUG) {return;}}switch (index) {case Log.VERBOSE:Log.v(tag, str.toString());break;case Log.DEBUG:Log.d(tag, str.toString());break;case Log.INFO:Log.i(tag, str.toString());break;case Log.WARN:Log.w(tag, str.toString());break;case Log.ERROR:Log.e(tag, str.toString());break;default:break;}} }
總結(jié)
以上是生活随笔為你收集整理的Android log 管理工具的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java 枚举类的基本使用
- 下一篇: EditText 显示明文和密码