创建Log 日志输出Util 可以直接定位日志所在类,所在方法, 以及打印行数

代码如下:




/***
 * 设置log 输出 打印行数据;
 */

public class Log {

    //所有使用这个类的应用,日志都将使用这个标签前缀。
    private static final String GLOBAL_TAG = "CameraApp";

    //也就是在开发版中(userdebug)该值为真打印log 日志,在用户版本(user )为false  不打印log 日志,控制日志的开关;
    public static final boolean DEBUG;
    //在'userdebug'变体中运行时为真,日志级别高于VERBOSE。
    public static final boolean VERBOSE;


    static {
        //判断是否是开发版;
       // DEBUG = Build.TYPE.equals("userdebug");
        //强制打印日志;
        DEBUG = true;

       // isLoggable是android.util.Log提供的方法,用于检查指定TAG的level,
        //参数1 输出的标签前缀; 参数2 输出等级level >=大于设定的值的日志会被打印出来;isLoggable返回true,反之则返回false;

/*
        *//**
         * Priority constant for the println method; use Log.v.
         *//*
        public static final int VERBOSE = 2;

        *//**
         * Priority constant for the println method; use Log.d.
         *//*
        public static final int DEBUG = 3;

        *//**
         * Priority constant for the println method; use Log.i.
         *//*
        public static final int INFO = 4;

        *//**
         * Priority constant for the println method; use Log.w.
         *//*
        public static final int WARN = 5;

        *//**
         * Priority constant for the println method; use Log.e.
         *//*
        public static final int ERROR = 6;

        *//**
         * Priority constant for the println method.
         *//*
        public static final int ASSERT = 7;*/

        //输出等级的设置有如上几种
        VERBOSE = DEBUG && android.util.Log.isLoggable(GLOBAL_TAG, android.util.Log.VERBOSE);
    }

    /***
     * 组装一个TAG 对象;传入的是关键子字符串;
     */
    public static final class Tag {

        final String mValue;

        public Tag(String tag) {
            this.mValue = tag;
        }

        @Override
        public String toString() {
            return mValue;
        }
    }





    /**
     * TAG 中放置的是一个刷选标签的名字,除了前缀我们可以拿此标签进行日志的筛选;
     *  msg 是我们输出的日志内容;
     */
    public static void v(Tag tag, String... msg) {
        if (VERBOSE) {
            android.util.Log.v(GLOBAL_TAG, makeLogStringWithLongInfo(tag, msg));
        }
    }

    /**
     * Please use new version v(String, Throwable).
     * @deprecated
     */
    public static void v(Tag tag, String msg, Throwable tr) {
        if (VERBOSE) {
            android.util.Log.v(GLOBAL_TAG, makeLogStringWithLongInfo(tag, msg), tr);
        }
    }

    /**
     * Enabled if running in 'userdebug' variant and Log level is higher than VERBOSE.
     */
    public
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值