android学习笔记——灵活使用Log打印日志
来源:互联网 发布:淘宝模特工资一般多少 编辑:程序博客网 时间:2024/05/15 23:47
我们都知道android的日志打印能够帮助我们快速定位错误,以及帮助我们获取重要信息。但是,当我们需要发布我们的项目时,我们不能让这些日志继续打印执行,得让他们都不工作,但是项目一大,你不可能一条一条的去删Log吧,所以,我们得想一个更好的办法来解决这个问题。
我们尝试写一个这样的类
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);
}
}
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);
}
}
}
当我们需要去打印日志的时候使用这个类的方法,LogUtil.e("TAG" , "error log");
同样可以打印出日志信息。而当我们的项目需要上线的时候,只需要将LEVEL的级别调整到NOTHING上来,就不会再打印出信息了。
0 0
- android学习笔记——灵活使用Log打印日志
- android打印log日志
- Android学习笔记11---Log日志初探
- Android Log日志规则打印
- Android NDK(学习笔记四)—— 在NDK开发中JNI打印Log信息
- Android中吐司Toast、打印日志Log的使用
- 在Android应用中使用Log打印日志信息
- Android Log 日志调试(打印日志)
- android学习笔记4--------------日志打印
- Android日志Log使用
- android日志工具—Log
- swift学习日志—— Log日志
- Android调试不打印log日志
- Android Jni NDK 打印log日志
- 【Android Util】全局控制Log打印日志
- android中Log打印日志相关信息
- Android log 日志打印简单封装
- Android学习笔记——日志工具的使用
- JAVA字符串格式化
- android学习笔记——使用Intent传递对象
- Java笔记 – 泛型 泛型方法 泛型接口 擦除 边界 通配符
- 基于HttpClient的HttpUtils(后台访问URL)
- 深度探索C++注释
- android学习笔记——灵活使用Log打印日志
- 集成Tomcat插件到Eclipse
- 51nod--1183 编辑距离(动态规划)
- 运行时动态方法交换
- 整数的十进制、二进制、八进制与十六进制
- Apache Commons fileUpload实现文件上传
- Thinkphp的RBAC权限管理
- 感知机Python实现
- 三十分钟掌握STL using STL