android Log控制小技巧--BuildConfig.DEBUG的使用
来源:互联网 发布:h5 js 打开支付宝app 编辑:程序博客网 时间:2024/05/16 07:45
log控制输出,有个小技巧:
ADT(r17)中添加了一个新功能可以允许开发者只在debug模式下允许某些代码,Build系统会自动生成一个BuilldConfig的类,里面包含一个DEBUG静态常量,该常量可以根据Build类型自动设置值,利用此常量可以编写debug模式下跑的代码,而不再需要手动配置变量,避免忘记修改在release版本泄露debug信息。日志类可以这么写:
import android.util.Log;import static com.jjx.hope.BuildConfig.DEBUG;;public final class L {public static void d(String tag, String str) {if (DEBUG) {Log.d(tag, str);}}public static void v(String tag, String str) {if (DEBUG) {Log.v(tag, str);}}public static void i(String tag, String str) {if (DEBUG) {Log.i(tag, str);}}public static void e(String tag, String str) {if (DEBUG) {Log.e(tag, str);}}/** * 打印当前方法的调用栈 * @param Tag * @param printDepth 打印的最大调用层数,若为0,只打印当前方法信息 */public static void printMethodCallStack(String Tag, int printDepth){ if (DEBUG) {StackTraceElement stack[] = (new Throwable()).getStackTrace();StackTraceElement stackTraceElement = null;int depth = Math.min(stack.length, printDepth + 2);for (int i = 1; i < depth; i++) {stackTraceElement = stack[i];Log.i(Tag, "["+(i-1)+"]"+stackTraceElement.getClassName()+"."+stackTraceElement.getMethodName()+"(...)");Log.i(Tag, "--"+stackTraceElement.getFileName()+"#"+stackTraceElement.getLineNumber()); }}}}
情怀
0 0
- android Log控制小技巧--BuildConfig.DEBUG的使用
- Android BuildConfig.DEBUG的使用
- android中BuildConfig.DEBUG的使用
- Android开发中BuildConfig.DEBUG的使用
- android中BuildConfig.DEBUG的使用
- android中BuildConfig.DEBUG的使用
- Android BuildConfig.DEBUG的使用详解
- android中BuildConfig.DEBUG的使用
- BuildConfig.DEBUG的使用
- BuildConfig:Android BuildConfig.DEBUG的妙用
- 【android】利用BuildConfig.DEBUG来控制日志的输出
- Android BuildConfig.DEBUG的妙用
- Android BuildConfig.DEBUG的妙用
- android BuildConfig Debug的妙用
- android BuildConfig.DEBUG的妙用
- Android BuildConfig.DEBUG的妙用
- ANDROID BUILDCONFIG.DEBUG的妙用
- Android BuildConfig.DEBUG的妙用(Eclipse)
- 调用系统界面,给指定的号码发送短信,附带短信内容
- WPF图片模糊
- Win 快捷键
- Android中的基本控件
- <meta property="og:需要写的标签"的应用
- android Log控制小技巧--BuildConfig.DEBUG的使用
- js中 location对象的使用
- HTTP 1.1与HTTP 1.0的比较 -- linux内核
- GCD使用攻略
- 0-1背包问题
- popcorn maker在线视频编辑工具的配置及相关设置
- Best Time to Buy and Sell Stock III
- 分析一下B2B网站运营的几点要求
- hub_config