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; } } }