Android 工具类 - Log

搞开发已经两年半了,以前都没有总结过自己写过或者看多的代码,以后准备开始总结好的代码,作为自己的工具类

这个是开发中打印LOG的工具类:

package com.andy.utils;

import android.util.Log;

/**
 * 对Log级别进行管理
 * currentLogLevel 设置级别
 * @author	Andy
 * @email	jwc0310@163.com
 */

public class LG {

	private final static String TAG_GLOBAL = "Andy";

	/**
     * Priority constant for the println method; use Log.v.
     *
    public static final int VERBOSE = 2;

     *
     * Priority constant for the println method; use Log.d.
     *
    public static final int DEBUG = 3;

     *
     * Priority constant for the println method; use Log.i.
     *
    public static final int INFO = 4;

     *
     * Priority constant for the println method; use Log.w.
     *
    public static final int WARN = 5;

	 *
     * Priority constant for the println method; use Log.e.
     *
    public static final int ERROR = 6;
    
	 *
     * Priority constant for the println method.
     *
    public static final int ASSERT = 7;
    *
	*/
	
	/**
	 * log level
	 * Log
	 */

	public static int currentLogLevel = Log.VERBOSE; 
	/**
	 * Verbose
	 * @param clazz
	 * @param msg
	 */
	public static void v(Class<?> clazz, String msg){
		if(currentLogLevel > Log.VERBOSE){
			return;
		}
		Log.v(TAG_GLOBAL, "["+clazz.getSimpleName()+"]: "+msg);
	}

	/**
	 * Debug
	 * @param clazz
	 * @param msg
	 */
	public static void d(Class<?> clazz, String msg){
		if(currentLogLevel > Log.DEBUG){
			return;
		}
		Log.d(TAG_GLOBAL, "["+clazz.getSimpleName()+"]: "+msg);
	}

	/**
	 * Info
	 * @param clazz
	 * @param msg
	 */
	public static void i(Class<?> clazz, String msg){
		if(currentLogLevel > Log.INFO){
			return;
		}
		Log.i(TAG_GLOBAL, "["+clazz.getSimpleName()+"]: "+msg);
	}

	/**
	 * Warning
	 * @param clazz
	 * @param msg
	 */
	public static void w(Class<?> clazz, String msg){
		if(currentLogLevel > Log.WARN){
			return;
		}
		Log.w(TAG_GLOBAL, "["+clazz.getSimpleName()+"]: "+msg);
	}
	
	/**
	 * Error
	 * @param clazz
	 * @param msg
	 */
	public static void e(Class<?> clazz, String msg){
		if(currentLogLevel > Log.ERROR){
			return;
		}
		Log.e(TAG_GLOBAL, "["+clazz.getSimpleName()+"]: "+msg);
	}
	
	private LG(){
		/* cannot be instantiated */
		throw new UnsupportedOperationException("cannot be instantiated");
	}
	
}

下载地址


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值