/** * 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); } }
版权声明:本文博主原创文章,博客,未经同意不得转载。