工具类Log
2016-04-29 22:20
302 查看
在这里分享一个工具类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);}}显示不出结果,不知道是为什么,有小伙伴知道,欢迎留言,谢谢。
相关文章推荐
- 使用KMS批量激活操作系统
- 删除ORacle 命名空间
- Dubbo与Zookeeper、SpringMVC整合和使用(负载均衡、容错)
- 冲刺第六天
- 15.oracle的dump理解十五 SQL命令DUMP
- Corosync+Pacemaker+MySQL+DRBD(二) 推荐
- 14.oracle的dump理解十四 窥视内存
- 构建之法阅读笔记01
- 13.oracle的dump理解十二 dump heap
- 后缀数组 POJ 3581 Sequence
- 12.oracle的dump理解十二 dump library_cache_object
- 2.Python操作Redis:列表(List)
- 【图文详解】scrapy爬虫与动态页面——爬取拉勾网职位信息(1)
- 【图文详解】scrapy爬虫与动态页面——爬取拉勾网职位信息(1)
- wordpress必装的插件 wp最常用的十个插件
- 请问如何突破”所选文件超出了文件的最大值设定:25.00 Mb“限制
- 11.oracle的dump理解十一 dump library_cache
- Codeforces Round #347 (Div. 2)-B. Rebus(模拟)
- c++ valarrays
- Struts2表单验证、模型驱动、防重复提交、数据回显笔记整理 文章标题