zoukankan      html  css  js  c++  java
  • android打印日志封装

    public class LogUtils {
        static String className;//类名
        static String methodName;//方法名
        static int lineNumber;//行数
    
        private LogUtils(){
            /* Protect from instantiations */
        }
    
        public static boolean isDebuggable() {
            return BuildConfig.DEBUG;
        }
    
        private static String createLog( String log ) {
            StringBuffer buffer = new StringBuffer();
            buffer.append(methodName);
            buffer.append("(").append(className).append(":").append(lineNumber).append(")");
            buffer.append(log);
            return buffer.toString();
        }
    
        private static void getMethodNames(StackTraceElement[] sElements){
            className = sElements[1].getFileName();
            methodName = sElements[1].getMethodName();
            lineNumber = sElements[1].getLineNumber();
        }
    
    
        public static void e(String message){
            if (!isDebuggable())
                return;
    
            // Throwable instance must be created before any methods
            getMethodNames(new Throwable().getStackTrace());
            Log.e(className, createLog(message));
        }
    
    
        public static void i(String message){
            if (!isDebuggable())
                return;
    
            getMethodNames(new Throwable().getStackTrace());
            Log.i(className, createLog(message));
        }
    
        public static void d(String message){
            if (!isDebuggable())
                return;
    
            getMethodNames(new Throwable().getStackTrace());
            Log.d(className, createLog(message));
        }
    
        public static void v(String message){
            if (!isDebuggable())
                return;
    
            getMethodNames(new Throwable().getStackTrace());
            Log.v(className, createLog(message));
        }
    
        public static void w(String message){
            if (!isDebuggable())
                return;
    
            getMethodNames(new Throwable().getStackTrace());
            Log.w(className, createLog(message));
        }
    
        public static void wtf(String message){
            if (!isDebuggable())
                return;
    
            getMethodNames(new Throwable().getStackTrace());
            Log.wtf(className, createLog(message));
        }
    
  • 相关阅读:
    Luogu P1247 取火柴游戏
    Luogu P2148 [SDOI2009]E&D
    Luogu P3305 [SDOI2013]费用流 二分 网络流
    NTT学习笔记
    Luogu P4015 运输问题
    Lucas定理学习笔记(没有ex_lucas)
    Luogu P2613 【模板】有理数取余
    欧拉定理与扩展欧拉定理学习笔记
    BSGS与exBSGS学习笔记
    Luogu P3868 [TJOI2009]猜数字
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/10007840.html
Copyright © 2011-2022 走看看