日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

经常使用Log日志打印输出

發布時間:2024/9/5 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 经常使用Log日志打印输出 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/*** log刊物* @author Jenly* */ public class LogUtils {public static final String TAG = "Jenly";private static final String COLON = ":";private static final String ARROW = "->";/** 是否顯示Log日志 */private static boolean isShowLog = true;/** Log日志優先權 */private static int priority = 1;/*** Priority constant for the println method;use System.out.println*/public static final int PRINTLN = 1;/*** Priority constant for the println method; use Log.v.*/public static final int VERBOSE = 2;/*** Priority constant for the println method; use Log.d.*/public static final int DEBUG = 3;/*** Priority constant for the println method; use Log.i.*/public static final int INFO = 4;/*** Priority constant for the println method; use Log.w.*/public static final int WARN = 5;/*** Priority constant for the println method; use Log.e.*/public static final int ERROR = 6;/*** Priority constant for the println method.use Log.wtf.*/public static final int ASSERT = 7;public static void setShowLog(boolean isShowLog){LogUtils.isShowLog = isShowLog;}public static boolean isShowLog(){return isShowLog;}public static int getPriority() {return priority;}public static void setPriority(int priority) {LogUtils.priority = priority;}//-----------------------------------Log.v/*** Log.v* @param e*/public static void v(Throwable e) {if (isShowLog && priority <= VERBOSE)v(TAG,e);}public static void v(String tag,Throwable e) {if (isShowLog && priority <= VERBOSE)for(int i=0;i<e.getStackTrace().length;i++)Log.v(tag,new StringBuilder().append(e.getStackTrace()[i].getLineNumber()).append(COLON).append(e.getStackTrace()[i].getClassName()).append(ARROW).append(e.getStackTrace()[i].getMethodName()).append(COLON).append(e.getMessage()).toString());}public static void v(Throwable e,String msg) {if (isShowLog && priority <= VERBOSE)v(TAG,e,msg);}public static void v(String tag,Throwable e,String msg) {if (isShowLog && priority <= VERBOSE)for(int i=0;i<e.getStackTrace().length;i++)Log.v(tag,new StringBuilder().append(e.getStackTrace()[i].getLineNumber()).append(COLON).append(e.getStackTrace()[i].getClassName()).append(ARROW).append(e.getStackTrace()[i].getMethodName()).append(COLON).append(msg).toString(),e);}public static void v(String msg) {if (isShowLog && priority <= VERBOSE)v(TAG, msg);}public static void v(String tag, String msg) {if (isShowLog && priority <= VERBOSE)Log.v(tag, msg);}public static void v(Class<?

> cls, String msg) { if (isShowLog && priority <= VERBOSE) v(TAG,cls,msg); } public static void v(String tag,Class<?> cls,String msg) { if (isShowLog && priority <= VERBOSE) Log.v(tag, new StringBuilder() .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } public static void v(Class<?> cls, String line, String msg) { if (isShowLog && priority <= VERBOSE) v(TAG,cls,line,msg); } public static void v(String tag,Class<?> cls, String line, String msg) { if (isShowLog && priority <= VERBOSE) Log.e(tag, new StringBuilder() .append(line).append(COLON) .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } //-----------------------------------Log.d /** * Log.d * @param e */ public static void d(Throwable e) { if (isShowLog && priority <= DEBUG) d(TAG,e); } public static void d(String tag,Throwable e) { if (isShowLog && priority <= DEBUG) for(int i=0;i<e.getStackTrace().length;i++) Log.d(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(e.getMessage()) .toString()); } public static void d(Throwable e,String msg) { if (isShowLog && priority <= DEBUG) d(TAG,e,msg); } public static void d(String tag,Throwable e,String msg) { if (isShowLog && priority <= DEBUG) for(int i=0;i<e.getStackTrace().length;i++) Log.d(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(msg) .toString(),e); } public static void d(String msg) { if (isShowLog && priority <= DEBUG) d(TAG, msg); } public static void d(String tag, String msg) { if (isShowLog && priority <= DEBUG) Log.d(tag, msg); } public static void d(Class<?> cls, String msg) { if (isShowLog && priority <= DEBUG) d(TAG,cls,msg); } public static void d(String tag,Class<?> cls,String msg) { if (isShowLog && priority <= DEBUG) Log.d(tag, new StringBuilder() .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } public static void d(Class<?> cls, String line, String msg) { if (isShowLog && priority <= DEBUG) d(TAG,cls,line,msg); } public static void d(String tag,Class<?

> cls, String line, String msg) { if (isShowLog && priority <= DEBUG) Log.d(tag, new StringBuilder() .append(line).append(COLON) .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } //-----------------------------------Log.i /** * Log.i * @param e */ public static void i(Throwable e) { if (isShowLog && priority <= INFO) i(TAG,e); } public static void i(String tag,Throwable e) { if (isShowLog && priority <= INFO) for(int i=0;i<e.getStackTrace().length;i++) Log.i(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(e.getMessage()) .toString()); } public static void i(Throwable e,String msg) { if (isShowLog && priority <= INFO) i(TAG,e,msg); } public static void i(String tag,Throwable e,String msg) { if (isShowLog && priority <= INFO) for(int i=0;i<e.getStackTrace().length;i++) Log.i(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(msg) .toString(),e); } public static void i(String msg) { if (isShowLog && priority <= INFO) i(TAG, msg); } public static void i(String tag, String msg) { if (isShowLog && priority <= INFO) Log.i(tag, msg); } public static void i(Class<?> cls, String msg) { if (isShowLog && priority <= INFO) i(TAG,cls,msg); } public static void i(String tag,Class<?

> cls,String msg) { if (isShowLog && priority <= INFO) Log.i(tag, new StringBuilder() .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } public static void i(Class<?> cls, String line, String msg) { if (isShowLog && priority <= INFO) v(TAG,cls,line,msg); } public static void i(String tag,Class<?> cls, String line, String msg) { if (isShowLog && priority <= INFO) Log.i(tag, new StringBuilder() .append(line).append(COLON) .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } //-----------------------------------Log.w /** * Log.w * @param e */ public static void w(Throwable e) { if (isShowLog && priority <= WARN) w(TAG,e); } public static void w(String tag,Throwable e) { if (isShowLog && priority <= WARN) for(int i=0;i<e.getStackTrace().length;i++) Log.w(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(e.getMessage()) .toString()); } public static void w(Throwable e,String msg) { if (isShowLog && priority <= WARN) w(TAG,e,msg); } public static void w(String tag,Throwable e,String msg) { if (isShowLog && priority <= WARN) for(int i=0;i<e.getStackTrace().length;i++) Log.w(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(msg) .toString(),e); } public static void w(String msg) { if (isShowLog && priority <= WARN) w(TAG, msg); } public static void w(String tag, String msg) { if (isShowLog && priority <= WARN) Log.w(tag, msg); } public static void w(Class<?> cls, String msg) { if (isShowLog && priority <= WARN) w(TAG,cls,msg); } public static void w(String tag,Class<?> cls,String msg) { if (isShowLog && priority <= WARN) Log.w(tag, new StringBuilder() .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } public static void w(Class<?> cls, String line, String msg) { if (isShowLog && priority <= WARN) w(TAG,cls,line,msg); } public static void w(String tag,Class<?> cls, String line, String msg) { if (isShowLog && priority <= WARN) Log.w(tag, new StringBuilder() .append(line).append(COLON) .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } //-----------------------------------Log.e /** * Log.e * @param e */ public static void e(Throwable e) { if (isShowLog && priority <= ERROR) e(TAG,e); } public static void e(String tag,Throwable e) { if (isShowLog && priority <= ERROR) for(int i=0;i<e.getStackTrace().length;i++) Log.e(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(e.getMessage()) .toString()); } public static void e(Throwable e,String msg) { if (isShowLog && priority <= ERROR) e(TAG,e,msg); } public static void e(String tag,Throwable e,String msg) { if (isShowLog && priority <= ERROR) for(int i=0;i<e.getStackTrace().length;i++) Log.e(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(msg) .toString(),e); } public static void e(String msg) { if (isShowLog && priority <= ERROR) e(TAG, msg); } public static void e(String tag, String msg) { if (isShowLog && priority <= ERROR) Log.e(tag, msg); } public static void e(Class<?> cls, String msg) { if (isShowLog && priority <= ERROR) e(TAG,cls,msg); } public static void e(String tag,Class<?> cls,String msg) { if (isShowLog && priority <= ERROR) Log.e(tag, new StringBuilder() .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } public static void e(Class<?> cls, String line, String msg) { if (isShowLog && priority <= ERROR) e(TAG,cls,line,msg); } public static void e(String tag,Class<?> cls, String line, String msg) { if (isShowLog && priority <= ERROR) Log.w(tag, new StringBuilder() .append(line).append(COLON) .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } //-----------------------------------Log.wtf /** * Log.wtf * @param e */ public static void wtf(Throwable e) { if (isShowLog && priority <= ASSERT) wtf(TAG,e); } public static void wtf(String tag,Throwable e) { if (isShowLog && priority <= ASSERT) for(int i=0;i<e.getStackTrace().length;i++) Log.wtf(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(e.getMessage()) .toString()); } public static void wtf(Throwable e,String msg) { if (isShowLog && priority <= ASSERT) wtf(TAG,e,msg); } public static void wtf(String tag,Throwable e,String msg) { if (isShowLog && priority <= ASSERT) for(int i=0;i<e.getStackTrace().length;i++) Log.wtf(tag, new StringBuilder() .append(e.getStackTrace()[i].getLineNumber()) .append(COLON) .append(e.getStackTrace()[i].getClassName()) .append(ARROW) .append(e.getStackTrace()[i].getMethodName()) .append(COLON) .append(msg) .toString(),e); } public static void wtf(String msg) { if (isShowLog && priority <= ASSERT) wtf(TAG, msg); } public static void wtf(String tag, String msg) { if (isShowLog && priority <= ASSERT) Log.wtf(tag, msg); } public static void wtf(Class<?> cls, String msg) { if (isShowLog && priority <= ASSERT) wtf(TAG,cls,msg); } public static void wtf(String tag,Class<?> cls,String msg) { if (isShowLog && priority <= ASSERT) Log.wtf(tag, new StringBuilder() .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } public static void wtf(Class<?> cls, String line, String msg) { if (isShowLog && priority <= ASSERT) e(TAG,cls,line,msg); } public static void wtf(String tag,Class<?

> cls, String line, String msg) { if (isShowLog && priority <= ASSERT) Log.wtf(tag, new StringBuilder() .append(line).append(COLON) .append(cls.getSimpleName()) .append(COLON) .append(msg) .toString()); } //-----------------------------------System.out.print /** * System.out.print * @param msg */ public static void print(String msg){ if(isShowLog && priority <= PRINTLN) System.out.print(msg); } public static void print(Object obj){ if(isShowLog && priority <= PRINTLN) System.out.print(obj); } //-----------------------------------System.out.printf /** * System.out.printf * @param msg */ public static void printf(String msg){ if(isShowLog && priority <= PRINTLN) System.out.printf(msg); } //-----------------------------------System.out.println /** * System.out.println * @param msg */ public static void println(String msg){ if(isShowLog && priority <= PRINTLN) System.out.println(msg); } public static void println(Object obj){ if(isShowLog && priority <= PRINTLN) System.out.println(obj); } }


只需進行一個簡單的包、方便記錄和管理、

版權聲明:本文博主原創文章,博客,未經同意不得轉載。

轉載于:https://www.cnblogs.com/zfyouxi/p/4854131.html

總結

以上是生活随笔為你收集整理的经常使用Log日志打印输出的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。