用法同android原生日志类
import android.util.Log;
import androidx.annotation.NonNull;
/**
* Util class for logging.
*
* @author caoyifan
*/
public class Logger {
private final static boolean DEBUG = true;
/**
* Logs verbose level logs if loggable.
*
* <p>@see String#format(String, Object...) for formatting log string.
*/
public static void v(String tag, @NonNull String msg, Object... args) {
if (DEBUG) {
Log.v(tag, String.format(msg, args));
}
}
/**
* Logs debug level logs if loggable.
*
* <p>@see String#format(String, Object...) for formatting log string.
*/
public static void d(String tag, @NonNull String msg, Object... args) {
if (DEBUG) {
Log.d(tag, msg);
}
}
/**
* Logs info level logs if loggable.
*
* <p>@see String#format(String, Object...) for formatting log string.
*/
public static void i(String tag, @NonNull String msg, Object... args) {
if (DEBUG) {
Log.i(tag, String.format(msg, args));
}
}
/**
* Logs warning level logs if loggable.
*
* <p>@see String#format(String, Object...) for formatting log string.
*/
public static void w(String tag, @NonNull String msg, Object... args) {
if (DEBUG) {
Log.w(tag, String.format(msg, args));
}
}
/**
* Logs error level logs.
*
* <p>@see String#format(String, Object...) for formatting log string.
*/
public static void e(String tag, @NonNull String msg, Object... args) {
Log.e(tag, String.format(msg, args));
}
/**
* Logs warning level logs.
*
* <p>@see String#format(String, Object...) for formatting log string.
*/
public static void e(String tag, Exception e, @NonNull String msg, Object... args) {
Log.e(tag, String.format(msg, args), e);
}
}
自定义Log类,用于启动或关闭日志
于 2024-07-03 10:14:09 首次发布