首页 > 代码库 > 常用的Log日志打印与输出

常用的Log日志打印与输出


/**
 * log日志
 * @author Jenly
 * 
 */
public class LogUtils {

	private static final String TAG = "Jenly";

	private static final String COLON = ":";

	private static final String ARROW = "->";

	/** 是否显示Log日志 */
	private static boolean isShowLog = true;
	
	
	public static void setIsShowLog(boolean isShow){
		
		isShowLog = isShow;
	}
	
	public static boolean getIsShoWlOG(){
		
		return isShowLog;
	}

	
	//-----------------------------------Log.v
	
	/**
	 * Log.v
	 * @param e
	 */
	public static void v(Throwable e) {
		if (isShowLog)
			v(TAG,e);
	}
	
	public static void v(String tag,Throwable e) {
		if (isShowLog)
			Log.v(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(e.getMessage())
						.toString());
	}
	
	public static void v(Throwable e,String msg) {
		if (isShowLog)
			v(TAG,e,msg);
	}
	
	public static void v(String tag,Throwable e,String msg) {
		if (isShowLog)
			Log.v(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(msg)
						.toString());
	}

	public static void v(String msg) {
		if (isShowLog)
			v(TAG, msg);

	}

	public static void v(String tag, String msg) {
		if (isShowLog)
			Log.v(tag, msg);

	}

	public static void v(Class<?> cls, String msg) {
		if (isShowLog)
			v(TAG,cls,msg);
	}
	
	public static void v(String tag,Class<?> cls,String msg) {
		if (isShowLog)
			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)
			v(TAG,cls,line,msg);
	}
	
	public static void v(String tag,Class<?> cls, String line, String msg) {
		if (isShowLog)
			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)
			d(TAG,e);
	}
	
	public static void d(String tag,Throwable e) {
		if (isShowLog)
			Log.d(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(e.getMessage())
						.toString());
	}
	
	public static void d(Throwable e,String msg) {
		if (isShowLog)
			d(TAG,e,msg);
	}
	
	public static void d(String tag,Throwable e,String msg) {
		if (isShowLog)
			Log.d(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(msg)
						.toString());
	}
	
	public static void d(String msg) {
		if (isShowLog)
			d(TAG, msg);
		
	}
	
	public static void d(String tag, String msg) {
		if (isShowLog)
			Log.d(tag, msg);
		
	}
	
	public static void d(Class<?> cls, String msg) {
		if (isShowLog)
			d(TAG,cls,msg);
	}
	
	public static void d(String tag,Class<?> cls,String msg) {
		if (isShowLog)
			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)
			d(TAG,cls,line,msg);
	}
	
	public static void d(String tag,Class<?> cls, String line, String msg) {
		if (isShowLog)
			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)
			i(TAG,e);
	}
	
	public static void i(String tag,Throwable e) {
		if (isShowLog)
			Log.i(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(e.getMessage())
						.toString());
	}
	
	public static void i(Throwable e,String msg) {
		if (isShowLog)
			i(TAG,e,msg);
	}
	
	public static void i(String tag,Throwable e,String msg) {
		if (isShowLog)
			Log.i(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(msg)
						.toString());
	}
	
	public static void i(String msg) {
		if (isShowLog)
			i(TAG, msg);
		
	}
	
	public static void i(String tag, String msg) {
		if (isShowLog)
			Log.i(tag, msg);
		
	}
	
	public static void i(Class<?> cls, String msg) {
		if (isShowLog)
			i(TAG,cls,msg);
	}
	
	public static void i(String tag,Class<?> cls,String msg) {
		if (isShowLog)
			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)
			v(TAG,cls,line,msg);
	}
	
	public static void i(String tag,Class<?> cls, String line, String msg) {
		if (isShowLog)
			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)
			w(TAG,e);
	}
	
	public static void w(String tag,Throwable e) {
		if (isShowLog)
			Log.w(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(e.getMessage())
						.toString());
	}
	
	public static void w(Throwable e,String msg) {
		if (isShowLog)
			w(TAG,e,msg);
	}
	
	public static void w(String tag,Throwable e,String msg) {
		if (isShowLog)
			Log.w(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(msg)
						.toString());
	}
	
	public static void w(String msg) {
		if (isShowLog)
			w(TAG, msg);
		
	}
	
	public static void w(String tag, String msg) {
		if (isShowLog)
			Log.w(tag, msg);
		
	}
	
	public static void w(Class<?> cls, String msg) {
		if (isShowLog)
			w(TAG,cls,msg);
	}
	
	public static void w(String tag,Class<?> cls,String msg) {
		if (isShowLog)
			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)
			w(TAG,cls,line,msg);
	}
	
	public static void w(String tag,Class<?> cls, String line, String msg) {
		if (isShowLog)
			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)
			e(TAG,e);
	}
	
	public static void e(String tag,Throwable e) {
		if (isShowLog)
			Log.e(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(e.getMessage())
						.toString());
	}
	
	public static void e(Throwable e,String msg) {
		if (isShowLog)
			e(TAG,e,msg);
	}
	
	public static void e(String tag,Throwable e,String msg) {
		if (isShowLog)
			Log.e(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(msg)
						.toString());
	}
	
	public static void e(String msg) {
		if (isShowLog)
			e(TAG, msg);
		
	}
	
	public static void e(String tag, String msg) {
		if (isShowLog)
			Log.e(tag, msg);
		
	}
	
	public static void e(Class<?> cls, String msg) {
		if (isShowLog)
			e(TAG,cls,msg);
	}
	
	public static void e(String tag,Class<?> cls,String msg) {
		if (isShowLog)
			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)
			e(TAG,cls,line,msg);
	}
	
	public static void e(String tag,Class<?> cls, String line, String msg) {
		if (isShowLog)
			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)
			wtf(TAG,e);
	}
	
	public static void wtf(String tag,Throwable e) {
		if (isShowLog)
			Log.wtf(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(e.getMessage())
						.toString());
	}
	
	public static void wtf(Throwable e,String msg) {
		if (isShowLog)
			wtf(TAG,e,msg);
	}
	
	public static void wtf(String tag,Throwable e,String msg) {
		if (isShowLog)
			Log.wtf(tag,
					new StringBuilder()
						.append(e.getStackTrace()[0].getLineNumber())
						.append(COLON)
						.append(e.getStackTrace()[0].getClassName())
						.append(ARROW)
						.append(e.getStackTrace()[0].getMethodName())
						.append(COLON)
						.append(msg)
						.toString());
	}
	
	public static void wtf(String msg) {
		if (isShowLog)
			wtf(TAG, msg);
		
	}
	
	public static void wtf(String tag, String msg) {
		if (isShowLog)
			Log.wtf(tag, msg);
		
	}
	
	public static void wtf(Class<?> cls, String msg) {
		if (isShowLog)
			wtf(TAG,cls,msg);
	}
	
	public static void wtf(String tag,Class<?> cls,String msg) {
		if (isShowLog)
			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)
			e(TAG,cls,line,msg);
	}
	
	public static void wtf(String tag,Class<?> cls, String line, String msg) {
		if (isShowLog)
			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)
			System.out.print(msg);
	}
	
	public static void print(Object obj){
		if(isShowLog)
			System.out.print(obj);
	}
	
	//-----------------------------------System.out.printf
	
	/**
	 * System.out.printf
	 * @param msg
	 */
	public static void printf(String msg){
		if(isShowLog)
			System.out.printf(msg);
	}
	
	//-----------------------------------System.out.println
	
	/**
	 * System.out.println
	 * @param msg
	 */
	public static void println(String msg){
		if(isShowLog)
			System.out.println(msg);
	}
	
	public static void println(Object obj){
		if(isShowLog)
			System.out.println(obj);
	}
	

}

只是进行了一个简单的封装、方便记录与管理、