工具类Log
来源:互联网 发布:苏州网络耗材批发 编辑:程序博客网 时间:2024/05/17 22:08
在这里分享一个工具类Log,简化打印Log的代码书写而且可以关闭Log的工具类
工具类
package com.pc.jiyuan.logtest;import android.annotation.SuppressLint;import android.util.Log;/** * * 打印log日志 可关闭,e红色 w橙色 i绿色 d蓝色 v黑色 */@SuppressLint("DefaultLocale")public class L {// !!! NOTE !!!// TODO: set it true when build for release versionpublic final static boolean mode_for_release = MyApplication.isRelease;public final static boolean server_switch = true;public final static String TAG = "livechannel";public static void I(String msg){if (!mode_for_release){Log.i("dream", msg);}}public static void v(String tag, String msg) {if (!mode_for_release)Log.v(tag, msg);}public static void v(String tag, String type, String msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%s", tag, type, msg);Log.v(TAG, des);}}public static void v(String tag, String type, String msg, String msg1) {if (!mode_for_release) {String des = String.format("[%s][%s]%s%s", tag, type, msg, msg1);Log.v(TAG, des);}}public static void v(String tag, String type, int msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%d", tag, type, msg);Log.v(TAG, des);}}public static void v(String tag, String type, boolean msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%s", tag, type, msg ? "true": "false");Log.v(TAG, des);}}public static void i(String tag, String type, String msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%s", tag, type, msg);Log.i(TAG, des);}}@SuppressLint("DefaultLocale")public static void i(String tag, String type, int msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%d", tag, type, msg);Log.v(TAG, des);}}public static void i(String tag, String msg) {i(tag, "", msg);}public static void i(String tag, String type, boolean msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%s", tag, type, msg ? "true": "false");Log.v(TAG, des);}}public static void e(String tag, String type, String msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%s", tag, type, msg);Log.e(TAG, des);}}@SuppressLint("DefaultLocale")public static void e(String tag, String type, int msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%d", tag, type, msg);Log.e(TAG, des);}}@SuppressLint("DefaultLocale")public static void e(String tag, String type, boolean msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%d", tag, type, msg ? "true": "false");Log.e(TAG, des);}}}
它所依赖的文件
package com.pc.jiyuan.logtest;import android.app.Application;import java.util.Map;/** * * Created by www_and on 2015/10/27. */public class MyApplication extends Application { public static boolean isRelease = false;// 设置打印日志 ,为true的时候为关闭 }
记得在Manifest文件application中注册
android:name = ".MyApplication"
我自己在学习这个工具类的时候,打印其他的Log比如public static void v(String tag, String type, String msg) {if (!mode_for_release) {String des = String.format("[%s][%s]%s", tag, type, msg);Log.v(TAG, des);}}
显示不出结果,不知道是为什么,有小伙伴知道,欢迎留言,谢谢。
0 0
- 【OpenSource】【Log】Log工具类
- Log工具类
- Android:log工具类
- android log工具类
- Android Log工具类
- Android 工具类 - Log
- Android Log 工具类
- Log工具类
- 工具类Log
- Log最佳工具类
- Log日志工具类
- Log 工具类
- Log日志工具类
- Log打印工具类
- Log日志工具类
- Android Log工具类
- Android Log工具类
- Log输出工具类
- 1.latch之latch redo allocation
- 第四课 初识系统调用
- android开发之提高应用启动速度_splash页面瞬间响应_避免APP启动闪白屏
- 2.latch之oracle latch
- 如何模拟cursor pin S
- 工具类Log
- 4.latch之oracle latch undo globaldata
- 开博感想
- C++primer plus 第三 四章的习题(自己写的)
- GO语言下载、安装、配置
- 7.oracle的dump理解七 enqueue理论及dump enqueues
- Android源码解析(十七)-->Activity布局加载流程
- Activity、Task、Application关系+Intent启动Flag
- Codeforces Round #347 (Div. 2)-B. Rebus(模拟)