工具类Log

在这里分享一个工具类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 version
	public 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);
		}
	}


显示不出结果,不知道是为什么,有小伙伴知道,欢迎留言,谢谢。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值