zoukankan      html  css  js  c++  java
  • Android Log工具类

    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    import android.util.Log;
    
    public class LogUtil {
    	private static final boolean DEBUG = true;
    	
    	public static void d(String TAG, String method, String msg) {
    		Log.d(TAG, "[" + method + "]" + msg);
    	}
    	
    	public static void d(String TAG, String msg){
    		if (DEBUG) {
    			Log.d(TAG, "[" + getFileLineMethod() + "]" + msg);
    		}
    	}
    	
    	public static void d(String msg){
    		if (DEBUG) {
    			Log.d(_FILE_(), "[" + getLineMethod() + "]" + msg);
    		}
    	}
    	
    	public static void e(String msg){
    		if (DEBUG) {
    			Log.e(_FILE_(), getLineMethod() + msg);
    		}
    	}
    	
    	public static void e(String TAG, String msg){
    		if (DEBUG) {
    			Log.e(TAG, getLineMethod() + msg);
    		}
    	}
    
    	public static String getFileLineMethod() {
    		StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
    		StringBuffer toStringBuffer = new StringBuffer("[")
    				.append(traceElement.getFileName()).append(" | ")
    				.append(traceElement.getLineNumber()).append(" | ")
    				.append(traceElement.getMethodName()).append("]");
    		return toStringBuffer.toString();
    	}
    	
    	public static String getLineMethod() {
    		StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
    		StringBuffer toStringBuffer = new StringBuffer("[")
    				.append(traceElement.getLineNumber()).append(" | ")
    				.append(traceElement.getMethodName()).append("]");
    		return toStringBuffer.toString();
    	}
    
    	public static String _FILE_() {
    		StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
    		return traceElement.getFileName();
    	}
    
    	public static String _FUNC_() {
    		StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    		return traceElement.getMethodName();
    	}
    
    	public static int _LINE_() {
    		StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    		return traceElement.getLineNumber();
    	}
    
    	public static String _TIME_() {
    		Date now = new Date();
    		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    		return sdf.format(now);
    	}
    }
    

      

  • 相关阅读:
    TRUNCATE TABLE 删除表中的所有行,而不记录单个行删除操作
    血腥!实况转播SQL注入全过程,让你知道危害有多大。
    DB2隔离级别设置
    使用解释工具分析SQL语句
    DB2的七种武器
    db2精华文档和论坛链接
    “饮水机”:形象比喻 深入浅出理解RAID
    DB2 数据库恢复测试
    IBM DB2 日常维护汇总
    镜像分割与高可用性灾难恢复
  • 原文地址:https://www.cnblogs.com/spring87/p/4504792.html
Copyright © 2011-2022 走看看