If you think the Android project RZAndroidBaseUtils listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.raizlabs.baseutils;
//www.java2s.comimport android.annotation.TargetApi;
import android.os.Build;
import android.util.Log;
/**
* Class which logs to the built in Android {@link Log}, but provides a
* mechanism to disable logging at different levels.
*
* @author Dylan James
*/publicclass Logger {
privatestaticint logFlags = LogLevel.WARNINGS | LogLevel.ERRORS;
/**
* Sets the log levels which will be logged to the Android {@link Log}.
* @param logLevel A bitmask of the desired levels, using values defined in
* {@link LogLevel}.
*/publicstaticvoid setLogLevel(int logLevel) { logFlags = logLevel; }
publicstaticvoid v(String tag, String msg) {
if ((logFlags & LogLevel.VERBOSE) > 0) {
Log.v(tag, msg);
}
}
publicstaticvoid v(String tag, String msg, Throwable tr) {
if ((logFlags & LogLevel.VERBOSE) > 0) {
Log.v(tag, msg, tr);
}
}
publicstaticvoid d(String tag, String msg) {
if ((logFlags & LogLevel.DEBUG) > 0) {
Log.d(tag, msg);
}
}
publicstaticvoid d(String tag, String msg, Throwable tr) {
if ((logFlags & LogLevel.DEBUG) > 0) {
Log.d(tag, msg, tr);
}
}
publicstaticvoid i(String tag, String msg) {
if ((logFlags & LogLevel.INFO) > 0) {
Log.i(tag, msg);
}
}
publicstaticvoid i(String tag, String msg, Throwable tr) {
if ((logFlags & LogLevel.INFO) > 0) {
Log.i(tag, msg, tr);
}
}
publicstaticvoid w(String tag, String msg) {
if ((logFlags & LogLevel.WARNINGS) > 0) {
Log.w(tag, msg);
}
}
publicstaticvoid w(String tag, String msg, Throwable tr) {
if ((logFlags & LogLevel.WARNINGS) > 0) {
Log.w(tag, msg, tr);
}
}
publicstaticvoid e(String tag, String msg) {
if ((logFlags & LogLevel.ERRORS) > 0) {
Log.e(tag, msg);
}
}
publicstaticvoid e(String tag, String msg, Throwable tr) {
if ((logFlags & LogLevel.ERRORS) > 0) {
Log.e(tag, msg, tr);
}
}
@TargetApi(Build.VERSION_CODES.FROYO)
publicstaticvoid wtf(String tag, String msg) {
if ((logFlags & LogLevel.WTF) > 0) {
Log.wtf(tag, msg);
}
}
@TargetApi(Build.VERSION_CODES.FROYO)
publicstaticvoid wtf(String tag, String msg, Throwable tr) {
if ((logFlags & LogLevel.WTF) > 0) {
Log.wtf(tag, msg, tr);
}
}
publicstaticclass LogLevel {
publicstaticfinalint VERBOSE = Integer.parseInt("000001", 2);
publicstaticfinalint DEBUG = Integer.parseInt("000010", 2);
publicstaticfinalint INFO = Integer.parseInt("000100");
publicstaticfinalint WARNINGS = Integer.parseInt("001000", 2);
publicstaticfinalint ERRORS = Integer.parseInt("010000", 2);
publicstaticfinalint WTF = Integer.parseInt("100000", 2);
publicstaticfinalint ALL = VERBOSE | DEBUG | INFO | WARNINGS | ERRORS | WTF;
publicstaticfinalint NONE = 0;
}
}