Android基础篇-日志管理类

本文介绍了一个用于Android平台的日志管理类,支持不同级别的日志输出,包括VERBOSE、DEBUG、INFO、WARN和ERROR,并提供了灵活的日志开关控制。
/**
 * @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);
        }
    }

}

转载于:https://www.cnblogs.com/gongcb/archive/2012/11/07/2758310.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值