可以输出类名、函数名以及所在行号的Log帮助类
2015-09-14 14:33
471 查看
/*** * This is free and unencumbered software released into the public domain. * * Anyone is free to copy, modify, publish, use, compile, sell, or * distribute this software, either in source code form or as a compiled * binary, for any purpose, commercial or non-commercial, and by any * means. * * For more information, please refer to <http://unlicense.org/> */ import android.text.TextUtils; import android.util.Log; import com.cpoopc.smoothemotionkeyboard.BuildConfig; /** * @date 21.06.2012 * @author Mustafa Ferhan Akman * * Create a simple and more understandable Android logs. * */ public class DebugLog { static String tagPrefix = "cp:"; static String className; static String methodName; static int lineNumber; private DebugLog() { /* Protect from instantiations */ } public static boolean isDebuggable() { return BuildConfig.DEBUG; } private static String createLog(String log) { StringBuffer buffer = new StringBuffer(); buffer.append("["); buffer.append(methodName); buffer.append(":"); buffer.append(lineNumber); buffer.append("]"); buffer.append(log); return buffer.toString(); } private static void getMethodNames(StackTraceElement[] sElements) { className = sElements[1].getFileName(); if (!TextUtils.isEmpty(tagPrefix)) { className = tagPrefix + className; } methodName = sElements[1].getMethodName(); lineNumber = sElements[1].getLineNumber(); } public static void e(String message) { if (!isDebuggable()) return; // Throwable instance must be created before any methods getMethodNames(new Throwable().getStackTrace()); Log.e(className, createLog(message)); } public static void i(String message) { if (!isDebuggable()) return; getMethodNames(new Throwable().getStackTrace()); Log.i(className, createLog(message)); } public static void d(String message) { if (!isDebuggable()) return; getMethodNames(new Throwable().getStackTrace()); Log.d(className, createLog(message)); } public static void v(String message) { if (!isDebuggable()) return; getMethodNames(new Throwable().getStackTrace()); Log.v(className, createLog(message)); } public static void w(String message) { if (!isDebuggable()) return; getMethodNames(new Throwable().getStackTrace()); Log.w(className, createLog(message)); } public static void wtf(String message) { if (!isDebuggable()) return; getMethodNames(new Throwable().getStackTrace()); Log.wtf(className, createLog(message)); } }
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories