在开发中经常会需要在代码中打印Log起到调试开发的作用,Android 自带的util.Log需要传递tag及msg,因此降低了开发效率。
这里给大家提供已封装好的log类,设置全局打印信息,并且增加日志开关。
public final class Log {
public static final String TAG = "Test";
public static final boolean DEBUG = true;
/**
* 详细的log
* @param msg
* @return
*/
public static int v(String msg){
if(DEBUG){
return android.util.Log.v(TAG,msg);
}
return 0;
}
/**
* 调试的log
* @param msg
* @return
*/
public static int d(String msg){
if(DEBUG){
return android.util.Log.d(TAG,msg);
}
return 0;
}
/**
* 信息log
* @param msg
* @return
*/
public static int i(String msg){
if(DEBUG){
return android.util.Log.i(TAG,msg);
}
return 0;
}
/**
* 警告log
* @param msg
* @return
*/
public static int w(String msg){
if(DEBUG){
return android.util.Log.w(TAG,msg);
}
return 0;
}
/**
* 错误log
* @param msg
* @return
*/
public static int e(String msg){
if(DEBUG){
return android.util.Log.e(TAG,msg);
}
return 0;
}
}