android上一个可追踪代码具体到函数某行的日志类
短信预约 -IT技能 免费直播动态提醒
代码如下:
代码如下:
package xiaogang.enif.utils;
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 adb logcat 命令查看日志详细介绍microlog4android将Android Log日志写到SD卡文件中实现方法Android 日志系统Logger源代码详细介绍Android开发之在程序中时时获取logcat日志信息的方法(附demo源码下载)Android SD卡上文件操作及记录日志操作实例分析Python实现过滤单个Android程序日志脚本分享logcat命令使用方法和查看android系统日志缓冲区内容的方法android轻松管理安卓应用中的log日志 发布应用时log日志全部去掉的方法android 捕获系统异常并上传日志具体实现Mac 下 Android Studio 不打印日志的解决办法
代码如下:
package xiaogang.enif.utils;
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 adb logcat 命令查看日志详细介绍microlog4android将Android Log日志写到SD卡文件中实现方法Android 日志系统Logger源代码详细介绍Android开发之在程序中时时获取logcat日志信息的方法(附demo源码下载)Android SD卡上文件操作及记录日志操作实例分析Python实现过滤单个Android程序日志脚本分享logcat命令使用方法和查看android系统日志缓冲区内容的方法android轻松管理安卓应用中的log日志 发布应用时log日志全部去掉的方法android 捕获系统异常并上传日志具体实现Mac 下 Android Studio 不打印日志的解决办法
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341