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);
            }
        }
    
    }
  • 相关阅读:
    线程池参数详解
    线程池各个参数详解以及如何自定义线程池
    fastdfs 安装
    SQL 执行顺序
    《SQL 进阶教程》 查找局部不一致的数据
    redis 高性能的原因
    一致性hash
    环境部署数据库报错
    redis 常用命令
    redis 高级学习和应用场景
  • 原文地址:https://www.cnblogs.com/gongcb/p/2758310.html
Copyright © 2011-2022 走看看