public class Log
extends java.lang.Object
Log by improving
the call to all log methods by supplying arguments as parameters '%s' instead of creating a string.
This avoids useless memory allocations when not requested: the StringBuilder itself, the buffer
and the String object. The new methods check in advance if the level is enabled and only after
the string message with arguments is created.
Note: This class can work in collaboration with Logger.
Others features are:
Use Log.Level.SUPPRESS to disable all logs. For instance:
if (BuildConfig.DEBUG) {
Log.setLevel(Level.INFO);
} else {
Log.setLevel(Level.SUPPRESS);
}
Log.i("Message arg1=%s, arg2=%s", arg1, arg2);
Logger| Modifier and Type | Class and Description |
|---|---|
static interface |
Log.Level
Annotation interface for log level:
Log.Level.VERBOSE, Log.Level.DEBUG, Log.Level.INFO,
Log.Level.WARN, Log.Level.ERROR, Log.Level.SUPPRESS |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
customTag |
| Modifier and Type | Method and Description |
|---|---|
static void |
d(java.lang.String msg,
java.lang.Object... args)
Sends a
Log.Level.DEBUG log message. |
static void |
e(java.lang.String msg,
java.lang.Object... args)
Sends an
Log.Level.ERROR log message. |
static void |
e(java.lang.Throwable t,
java.lang.String msg,
java.lang.Object... args)
Sends an
Log.Level.ERROR log message with the Exception at the end of the message. |
static void |
i(java.lang.String msg,
java.lang.Object... args)
Sends an
Log.Level.INFO log message. |
static boolean |
isDebugEnabled() |
static boolean |
isErrorEnabled() |
static boolean |
isInfoEnabled() |
static boolean |
isVerboseEnabled() |
static boolean |
isWarnEnabled() |
static void |
iTag(java.lang.String tag,
java.lang.String msg,
java.lang.Object... args)
As
i(String, Object...) but with custom tag for one call only. |
static void |
logMethodName(boolean method,
boolean line)
Allows to log method name and line number from where the log is called.
|
static void |
setLevel(int level) |
static void |
useTag(java.lang.String customTag)
Sets a general static custom tag for ALL log calls.
|
static void |
v(java.lang.String msg,
java.lang.Object... args)
Sends a
Log.Level.VERBOSE log message. |
static void |
w(java.lang.String msg,
java.lang.Object... args)
Sends a
Log.Level.WARN log message. |
static void |
w(java.lang.Throwable t,
java.lang.String msg,
java.lang.Object... args)
Sends a
Log.Level.WARN log message with the Exception at the end of the message. |
static void |
wtf(java.lang.String msg,
java.lang.Object... args)
What a Terrible Failure: Report a condition that should never happen.
|
static void |
wtf(java.lang.Throwable t,
java.lang.String msg,
java.lang.Object... args)
What a Terrible Failure: Report a condition that should never happen with the Exception
at the end of the message.
|
public static void setLevel(int level)
public static void logMethodName(boolean method,
boolean line)
- With method name: [method] msg.
- With line number: [method:line] msg.
method - true to print method name at the beginning of the message, false otherwiseline - true to print line number after the method name, false otherwisepublic static boolean isVerboseEnabled()
public static boolean isDebugEnabled()
public static boolean isInfoEnabled()
public static boolean isWarnEnabled()
public static boolean isErrorEnabled()
public static void v(java.lang.String msg,
java.lang.Object... args)
Log.Level.VERBOSE log message.msg - the message you would like loggedargs - the extra arguments for the messagepublic static void d(java.lang.String msg,
java.lang.Object... args)
Log.Level.DEBUG log message.msg - the message you would like loggedargs - the extra arguments for the messagepublic static void i(java.lang.String msg,
java.lang.Object... args)
Log.Level.INFO log message.msg - the message you would like loggedargs - the extra arguments for the messagepublic static void iTag(java.lang.String tag,
java.lang.String msg,
java.lang.Object... args)
i(String, Object...) but with custom tag for one call only.tag - custom tag, used to identify the source of a log messagemsg - the message you would like loggedargs - the extra arguments for the messagepublic static void w(java.lang.String msg,
java.lang.Object... args)
Log.Level.WARN log message.msg - the message you would like loggedargs - the extra arguments for the messagepublic static void w(java.lang.Throwable t,
java.lang.String msg,
java.lang.Object... args)
Log.Level.WARN log message with the Exception at the end of the message.t - The exception to logmsg - the message you would like loggedargs - the extra arguments for the messagepublic static void e(java.lang.String msg,
java.lang.Object... args)
Log.Level.ERROR log message.msg - the message you would like loggedargs - the extra arguments for the messagepublic static void e(java.lang.Throwable t,
java.lang.String msg,
java.lang.Object... args)
Log.Level.ERROR log message with the Exception at the end of the message.t - The exception to logmsg - the message you would like loggedargs - the extra arguments for the messagepublic static void wtf(java.lang.String msg,
java.lang.Object... args)
msg - the message you would like loggedargs - the extra arguments for the messagepublic static void wtf(java.lang.Throwable t,
java.lang.String msg,
java.lang.Object... args)
t - The exception to logmsg - the message you would like loggedargs - the extra arguments for the messagepublic static void useTag(java.lang.String customTag)
Note: If a Logger instance is created, this custom tag will be
reset to null and current filename will be used instead.
customTag - general static tag for ALL logs.