android的Log日志的打印管理工具类:

 package com.gzcivil.utils;

 import android.util.Log;

 /**
* 日志打印管理
*
* @author LiJinlun
* @time 2015-12-15
*/
public class LogUtils {
private static LogType mLogType;
private static String mDefaultPrefix = " --- "; static {
mLogType = LogType.ALL;
} /**
* 日志类型
*/
public enum LogType {
NONE, VERBOSE, DEBUG, INFO, WARN, ERROR, ALL
} /**
* 获取日志输出类型
*
* @return
*/
public static LogType getLogType() {
return mLogType;
} /**
* 设置日志输出类型
*
* @param mLogType
*/
public static void setLogType(LogType mLogType) {
LogUtils.mLogType = mLogType;
} public static final void e(String tag, Object... objects) {
if (logable(LogType.ERROR)) {
StrBuffer sb = new StrBuffer();
sb.append(mDefaultPrefix);
sb.append(objects);
Log.e(tag, sb.toString());
}
} public static final String getExceptionInfo(Throwable tr) {
return Log.getStackTraceString(tr);
} public static final void w(String tag, Object... objects) {
if (logable(LogType.WARN)) {
StrBuffer sb = new StrBuffer();
sb.append(mDefaultPrefix);
sb.append(objects);
Log.w(tag, sb.toString());
}
} public static final void i(String tag, Object... objects) {
if (logable(LogType.INFO)) {
StrBuffer sb = new StrBuffer();
sb.append(mDefaultPrefix);
sb.append(objects);
Log.i(tag, sb.toString());
}
} public static final void d(String tag, Object... objects) {
if (logable(LogType.DEBUG)) {
StrBuffer sb = new StrBuffer();
sb.append(mDefaultPrefix);
sb.append(objects);
Log.d(tag, sb.toString());
}
} public static final void v(String tag, Object... objects) {
if (logable(LogType.VERBOSE)) {
StrBuffer sb = new StrBuffer();
sb.append(mDefaultPrefix);
sb.append(objects);
Log.v(tag, sb.toString());
}
} private static final boolean logable(LogType aLogType) {
if (mLogType == LogType.ALL || mLogType == aLogType) {
return true;
}
return false;
} /**
* debug标签日志输出(建议仅在测试时使用改方法)
*
* @param objects
*/
public static final void debug(Object... objects) {
if (logable(LogType.DEBUG)) {
StrBuffer sb = new StrBuffer();
sb.append(mDefaultPrefix);
sb.append(objects);
Log.d("debug", sb.toString());
}
} }
05-04 07:38