代码如下:
/***
* 设置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