zoukankan      html  css  js  c++  java
  • 好用的log打印类

    package com.huawei.network.ott.weixin.util;
    
    
    import android.util.Log;
    
    public final class DebugLog {
    
    	/**
    	 * 描述级别的日志标识,该级别为日志最低级别,发布时将关闭
    	 */
    	public static final int VERBOSE = 0;
    	/**
    	 * 调试级别的日志标识,主要用于打印调试信息,发布时将关闭
    	 */
    	public static final int DEBUG = 1;
    	/**
    	 * 信息级别的日志标识,主要用于打印数据,属性等信息,发布时将关闭
    	 */
    	public static final int INFO = 2;
    	/**
    	 * 警告级别的日志标识,主要用于打印警告,发布时不关闭
    	 */
    	public static final int WARN = 3;
    	/**
    	 * 错误级别的日志标识,主要用于打印错误,发布时不关闭
    	 */
    	public static final int ERROR = 4;
    
    	private static boolean isPrintLog = true;
    	
    	private static int logLevel = VERBOSE;
    
    	/**
    	 * 是否打印日志
    	 * 
    	 * @return
    	 */
    	public static boolean isPrintLog() {
    		return isPrintLog;
    	}
    
    	/**
    	 * 设置是否打印日志
    	 * 
    	 * @param isPrintLog
    	 *            如果设置为true,则打印日志,否则将不打印日志
    	 */
    	public static void setPrintLog(boolean isPrintLog) {
    		DebugLog.isPrintLog = isPrintLog;
    	}
    
    	/**
    	 * 获取当前日志的打印最低Level
    	 * 
    	 * @return
    	 */
    	public static int getLogLevel() {
    		return logLevel;
    	}
    
    	/**
    	 * 设置当前日志的打印最低Level
    	 * 
    	 * @param logLevel
    	 */
    	public static void setLogLevel(int logLevel) {
    		DebugLog.logLevel = logLevel;
    	}
    
    	/**
    	 * 打印一个 {@link #VERBOSE} 日志信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 */
    	public static int v(String tag, String msg) {
    		if (isPrintLog && VERBOSE >= logLevel) {
    			return Log.v(tag, msg);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #VERBOSE} 日志信息并打印异常信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 * @param tr
    	 *            An exception to log
    	 */
    	public static int v(String tag, String msg, Throwable tr) {
    		if (isPrintLog && VERBOSE >= logLevel) {
    			return Log.v(tag, msg, tr);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #DEBUG} 日志信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 */
    	public static int d(String tag, String msg) {
    		if (isPrintLog && DEBUG >= logLevel) {
    			return Log.d(tag, msg);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #DEBUG} 日志信息并打印异常信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 * @param tr
    	 *            An exception to log
    	 */
    	public static int d(String tag, String msg, Throwable tr) {
    		if (isPrintLog && DEBUG >= logLevel) {
    			return Log.d(tag, msg, tr);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #INFO} 日志信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 */
    	public static int i(String tag, String msg) {
    		if (isPrintLog && INFO >= logLevel) {
    			return Log.i(tag, msg);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #INFO} 日志信息并打印异常信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 * @param tr
    	 *            An exception to log
    	 */
    	public static int i(String tag, String msg, Throwable tr) {
    		if (isPrintLog && INFO >= logLevel) {
    			return Log.i(tag, msg, tr);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #WARN} 日志信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 */
    	public static int w(String tag, String msg) {
    		if (isPrintLog && WARN >= logLevel) {
    			return Log.w(tag, msg);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #WARN} 异常信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 */
    	public static int w(String tag, Throwable tr) {
    		if (isPrintLog && WARN >= logLevel) {
    			return Log.w(tag, tr);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #WARN} 日志信息并打印异常信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 * @param tr
    	 *            An exception to log
    	 */
    	public static int w(String tag, String msg, Throwable tr) {
    		if (isPrintLog && WARN >= logLevel) {
    			return Log.w(tag, msg, tr);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #ERROR} 日志信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 */
    	public static int e(String tag, String msg) {
    		if (isPrintLog && ERROR >= logLevel) {
    			return Log.e(tag, msg);
    		} else {
    			return -1;
    		}
    	}
    
    	/**
    	 * 打印一个 {@link #ERROR} 日志信息并打印异常信息。
    	 * 
    	 * @param tag
    	 *            Used to identify the source of a log message. It usually
    	 *            identifies the class or activity where the log call occurs.
    	 * @param msg
    	 *            The message you would like logged.
    	 * @param tr
    	 *            An exception to log
    	 */
    	public static int e(String tag, String msg, Throwable tr) {
    		if (isPrintLog && ERROR >= logLevel) {
    			return Log.e(tag, msg, tr);
    		} else {
    			return -1;
    		}
    	}
    
    }
    

      

  • 相关阅读:
    SQL 判断字符包含在记录中出现了多少次
    JS 数据类型判断
    JS object转日期
    JS 日期转字符串
    Linux系统优化03-centos7网卡配置
    Linux系统安装02-centos7系统安装-分区及基本设置
    Linux系统安装01-centos7系统安装
    解决winserver2012R2安装VMware15(pro)问题
    Tomcat 如何设置Tomcat的标题,运行Tomcat显示为自己程序的命名
    IntelliJ Idea 常用快捷键列表
  • 原文地址:https://www.cnblogs.com/leihupqrst/p/4466234.html
Copyright © 2011-2022 走看看