zoukankan      html  css  js  c++  java
  • 可显示行号的log工具

    1. import android.util.Log;  
    2.   
    3. /** 
    4.  * (ExtendedLog=>ELog)可以记录行号,类名,方法名的Log工具 
    5.  *  
    6.  * @author Fantouch 
    7.  */  
    8. public class ELog {  
    9.     private static final boolean DEBUG = true;  
    10.     private static final String TAG = ELog.class.getSimpleName();  
    11.   
    12.     public static void e(String message) {  
    13.         if (DEBUG) {  
    14.             Log.e(getTag(Thread.currentThread().getStackTrace()), message);  
    15.         }  
    16.     }  
    17.   
    18.     public static void d(String message) {  
    19.         if (DEBUG) {  
    20.             Log.d(getTag(Thread.currentThread().getStackTrace()), message);  
    21.         }  
    22.     }  
    23.   
    24.     public static void i(String message) {  
    25.         if (DEBUG) {  
    26.             Log.i(getTag(Thread.currentThread().getStackTrace()), message);  
    27.         }  
    28.     }  
    29.   
    30.     public static void w(String message) {  
    31.         if (DEBUG) {  
    32.             Log.w(getTag(Thread.currentThread().getStackTrace()), message);  
    33.         }  
    34.     }  
    35.   
    36.     public static void v(String message) {  
    37.         if (DEBUG) {  
    38.             Log.v(getTag(Thread.currentThread().getStackTrace()), message);  
    39.         }  
    40.     }  
    41.   
    42.     private static String getTag(StackTraceElement[] elements) {  
    43.         StringBuffer tag = new StringBuffer();  
    44.         if (elements.length < 4) {  
    45.             Log.e(TAG, "Stack to shallow");  
    46.         } else {  
    47.             String fullClassName = elements[3].getClassName();  
    48.             tag.append(elements[3].getLineNumber() +  
    49.                     fullClassName.substring(fullClassName.lastIndexOf(".") + 1) + "." +  
    50.                     elements[3].getMethodName());  
    51.         }  
    52.         return tag.toString();  
    53.     }  
    54. }  
  • 相关阅读:
    P2522 [HAOI2011]Problem b(容斥)
    P3455 [POI2007]ZAP-Queries
    P2519 [HAOI2011]problem a(线段树优化dp+思维)
    P2516 [HAOI2010]最长公共子序列 (lcs+容斥)
    [HAOI2010]软件安装(缩点+树形dp)
    P2508 [HAOI2008]圆上的整点(神仙题)
    [SDOI2011]消防(树的直径+二分||单调队列)
    QLabel设置字体颜色
    Qt绘制不规则串口
    C++继承关系
  • 原文地址:https://www.cnblogs.com/dongweiq/p/10444313.html
Copyright © 2011-2022 走看看