Android工具类之LogUtil
2015-09-21 11:49
393 查看
package com.guan.o2o.utils; import android.util.Log; /** * @author Guan * @file com.guan.o2o.utils * @date 2015/9/21 * @Version 1.0 */ public class LogUtil { public static final int VERBOSE = 1; public static final int DEBUG = 2; public static final int INFO = 3; public static final int WARN = 4; public static final int ERROR = 5; public static final int NOTHING = 6; public static final int LEVEL = VERBOSE; public static void v(String tag, String msg) { if (LEVEL <= VERBOSE) { Log.v(tag, msg); } } public static void d(String tag, String msg) { if (LEVEL <= DEBUG) { Log.d(tag, msg); } } public static void i(String tag, String msg) { if (LEVEL <= INFO) { Log.i(tag, msg); } } public static void w(String tag, String msg) { if (LEVEL <= WARN) { Log.w(tag, msg); } } public static void e(String tag, String msg) { if (LEVEL <= ERROR) { Log.e(tag, msg); } } }
1、只有当 LEVEL常量的值小于或等于对应日志级别值 的时候,才会将日志打印出来。
2、LogUtil.d(“TAG”, “debug log”);
LogUtil.w(“TAG”, “warn log”);
3、需要修改 LEVEL常量的值,就可以自由地控制日志的打印行为了。比如让 LEVEL等于 VERBOSE 就可以把所有的日志都打印出来,让 LEVEL等于 WARN 就可以只 打印警告以上级别的日志,让 LEVEL等于 NOTHING就可以把所有日志都屏蔽掉。
4、使用了这种方法之后,刚才所说的那个问题就不复存在了,你只需要在开发阶段将 LEVEL指定成 VERBOSE,当项目正式上线的时候将 LEVEL指定成 NOTHING就可以了。
相关文章推荐
- 使用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