zoukankan      html  css  js  c++  java
  • Android基础篇日志管理类

    /**
     * @author gongchaobin
     * 
     * 日志管理
     * [统一管理日志,包括各种级别的日志]
     */
    public class Log {
    
        /**
         * 控制日志开关
         */
        private static boolean LogSwitch = true;
        
        
        /**
         * 打印verbose级别的日志
         * 
         * @param tag 标记
         * @param text 日志内容
         */
        public static void verbose(String tag, String text)
        {
            if (LogSwitch) {
                android.util.Log.w(tag,
                        text);
            }
        }
    
        /**
         * 
         * 打印debug级别的日志<BR>
         * [功能详细描述]
         * 
         * @param obj tag标记,传入当前调用的类对象即可,方法会转化为该对象对应的类名
         * @param text 日志内容
         */
        public static void debug(Object obj, String text)
        {
            if (LogSwitch) {
                if (obj != null)
                {
                    debug(obj.getClass().getSimpleName(),
                        text);
                }
            }
        }
    
        /**
         * 打印debug级别的日志
         * 
         * @param tag 标记
         * @param text 日志内容
         */
        public static void debug(String tag, String text)
        {
            if (LogSwitch) {
                android.util.Log.d(tag,
                    text);
            }
        }
    
        /**
         * 打印info级别的日志
         * 
         * @param tag 标记
         * @param text 日志内容
         */
        public static void info(String tag, String text)
        {
            if (LogSwitch) {
                android.util.Log.i(tag,
                        text);
            }
    
        }
    
        /**
         * 打印warn级别的日志
         * 
         * @param tag 标记
         * @param text 日志内容
         */
        public static void warn(String tag, String text)
        {
            if (LogSwitch) {
                android.util.Log.w(tag,
                    text);
            }
        }
    
        /**
         * 打印warn级别的日志
         * 
         * @param tag 标记
         * @param text 日志内容
         * @param throwable 异常信息
         */
        public static void warn(String tag, String text, Throwable throwable)
        {
            if (LogSwitch) {
                android.util.Log.w(tag,
                    text,
                    throwable);
            }
        }
    
        /**
         * 打印error级别的日志
         * 
         * @param tag 标记
         * @param text 日志内容
         */
        public static void error(String tag, String text)
        {
            if (LogSwitch) {
                android.util.Log.e(tag,
                    text);
            }
        }
    
        /**
         * 打印error级别的日志
         * 
         * @param tag 标记
         * @param text 日志内容
         * @param throwable 异常信息
         */
        public static void error(String tag, String text, Throwable throwable)
        {
            if (LogSwitch) {
                android.util.Log.e(tag,
                    text,
                    throwable);
            }
        }
    
    }
  • 相关阅读:
    python 数据结构与算法 day04 冒泡排序
    阿里代码扫描插件安装 (IDEA)
    Kafka
    女生赛训练 2
    2019 DISCS PrO High School Division
    计算机安全之密码安全 从 Hash 到 MD5
    CodeForces Round #559 Div.2
    CodeForces Round #558 Div.2
    CodeForces Round #560 Div.3
    NCD 2019 (AK)
  • 原文地址:https://www.cnblogs.com/gongcb/p/2758310.html
Copyright © 2011-2022 走看看