您的位置:首页 > 其它

工具类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);}}
显示不出结果,不知道是为什么,有小伙伴知道,欢迎留言,谢谢。

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: