手机
当前位置:查字典教程网 >编程开发 >安卓软件开发 >android上一个可追踪代码具体到函数某行的日志类
android上一个可追踪代码具体到函数某行的日志类
摘要:代码如下:复制代码代码如下:packagexiaogang.enif.utils;/***TheClassLogUtilsforlogpri...

代码如下:

复制代码 代码如下:

package xiaogang.enif.utils;

/**

* The Class LogUtils for log printing, which help us

* easy to trace our codes or logics in the project .

*

* @author zhao xiaogang

* @time 2011.4.12

*/

public class LogUtils {

private final static int VERBOSE = 0;

private final static int DEBUG = 1;

private final static int INFO = 2;

private final static int WARN = 3;

private final static int ERROR = 4;

private final static int DEFAULT_LEVEL = -1;

private int level;

private final String clazz;

private static final String TAG = "LogUtils";

public static LogUtils getDebugLog(Class<?> clazz, int l) {

LogUtils log = new LogUtils(clazz);

log.level = l;

return log;

}

public static LogUtils getLog(Class<?> clazz) {

return new LogUtils(clazz);

}

public LogUtils(Class<?> clazz) {

this.clazz = "[" + clazz.getSimpleName() + "] ";

level = DEFAULT_LEVEL;

}

public void verbose(String message) {

verbose(message, null);

}

public void debug(String message) {

debug(message, null);

}

public void info(String message) {

info(message, null);

}

public void warn(String message) {

warn(message, null);

}

public void error(String message) {

error(message, null);

}

public void verbose(String message, Throwable t) {

if (VERBOSE < level)

return;

if (message != null)

android.util.Log.v(TAG, clazz + " Line: " + getLineNumber() + " : " + message);

if (t != null)

android.util.Log.v(TAG, clazz + " Line: " + getLineNumber() + " : " + t.toString());

}

public void debug(String message, Throwable t) {

if (DEBUG < level)

return;

if (message != null)

android.util.Log.d(clazz, clazz + " Line: " + getLineNumber() + " : " + message);

if (t != null)

android.util.Log.d(clazz, clazz + " Line: " + getLineNumber() + " : " + t.toString());

}

public void info(String message, Throwable t) {

if (INFO < level)

return;

if (message != null)

android.util.Log.i(TAG, clazz + " Line: " + getLineNumber() + " : " + message);

if (t != null)

android.util.Log.i(TAG, clazz + " Line: " + getLineNumber() + " : " + t.toString());

}

public void warn(String message, Throwable t) {

if (WARN < level)

return;

if (message != null)

android.util.Log.w(TAG, clazz + " Line: " + getLineNumber() + " : " + message);

if (t != null)

android.util.Log.w(TAG, clazz + " Line: " + getLineNumber() + " : " + t.toString());

}

public void error(String message, Throwable t) {

if (ERROR < level)

return;

if (message != null)

android.util.Log.e(TAG, clazz + " Line: " + getLineNumber() + " : " + message);

if (t != null)

android.util.Log.e(TAG, clazz + " Line: " + getLineNumber() + " : " + t.toString());

}

private static int getLineNumber() {

return Thread.currentThread().getStackTrace()[5].getLineNumber();

}

}

好用的话,记得给好评,嘿嘿!

【android上一个可追踪代码具体到函数某行的日志类】相关文章:

Android不需要关闭后台运行程序

Android中 自定义数据绑定适配器BaseAdapter的方法

android 开发 文件读写应用案例分析

Android用代码获取手机root之后的最高权限

解析Android开发优化之:从代码角度进行优化的技巧

android 仿微信聊天气泡效果实现思路

基于Android开发支持表情的实现详解

android实现横屏的代码及思路

android 修改代码怎样编译

如何与Android实体设备的连接

精品推荐
分类导航