Android开发之非常好用的日志工具类(公司项目挖出来的)
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                Android开发之非常好用的日志工具类(公司项目挖出来的)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            /*** 日志相關類:默認是測試環境<br>* <b>支持:存儲Log日志文件到本地。發送Log日志信息到服務器</b>** @since 2016-5-13 14:31:21*/
public class LogUtils {public static boolean isDebug = true;private final static String APP_TAG = "demoUtils";/*** 獲取相關數據:類名,方法名,行號等.用來定位行<br>* at cn.utils.MainActivity.onCreate(MainActivity.java:17) 就是用來定位行的代碼<br>** @return [ Thread:main, at* cn.utils.MainActivity.onCreate(MainActivity.java:17)]*/private static String getFunctionName() {StackTraceElement[] sts = Thread.currentThread().getStackTrace();if (sts != null) {for (StackTraceElement st : sts) {if (st.isNativeMethod()) {continue;}if (st.getClassName().equals(Thread.class.getName())) {continue;}if (st.getClassName().equals(LogUtils.class.getName())) {continue;}return "[ Thread:" + Thread.currentThread().getName() + ", at " + st.getClassName() + "." + st.getMethodName()+ "(" + st.getFileName() + ":" + st.getLineNumber() + ")" + " ]";}}return null;}public static void v(String msg) {if (isDebug) {Log.v(APP_TAG, getMsgFormat(msg));}}public static void v(String tag, String msg) {if (isDebug) {Log.v(tag, getMsgFormat(msg));}}public static void d(String msg) {if (isDebug) {Log.d(APP_TAG, getMsgFormat(msg));}}public static void d(String tag, String msg) {if (isDebug) {Log.d(tag, getMsgFormat(msg));}}public static void i(String msg) {if (isDebug) {Log.i(APP_TAG, getMsgFormat(msg));}}public static void i(String tag, String msg) {if (isDebug) {Log.i(tag, getMsgFormat(msg));}}public static void w(String msg) {if (isDebug) {Log.w(APP_TAG, getMsgFormat(msg));}}public static void w(String tag, String msg) {if (isDebug) {Log.w(tag, getMsgFormat(msg));}}public static void e(String msg) {if (isDebug) {Log.e(APP_TAG, getMsgFormat(msg));}}public static void e(String tag, String msg) {if (isDebug) {Log.e(tag, getMsgFormat(msg));}}/*** 輸出格式定義*/private static String getMsgFormat(String msg) {return msg + " ;" + getFunctionName();}}
                            
                        
                        
                        總結
以上是生活随笔為你收集整理的Android开发之非常好用的日志工具类(公司项目挖出来的)的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 《暗黑3》法师技能搭配图文攻略
- 下一篇: Android开发之添加QQ群的方法(官
