public class Logger
extends java.lang.Object
Log by improving the call
to all log methods by supplying arguments as parameters 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 has best usage with Log.
Classical usage:
if (BuildConfig.DEBUG) {
Log.setLevel(Level.INFO);
} else {
Log.setLevel(Level.SUPPRESS);
}
Logger logger = new Logger("MyNewTag");
Advanced usage:
TheLogger constructor will reset the Log.customTag to null!
Log.v/d/i/w/e(...); it will log the current filename as tag.
public class MyClass {
private Logger logger;
public MyClass() {
if (Log.customTag == null) Log.useTag("MyClass");
this.logger = new Logger(Log.customTag);
...
}
public static void useTag(String tag) {
Log.useTag(tag);
}
}
// Usage
MyClass.useTag("MyNewSmartTag");
MyClass myClass = new MyClass();
Log| Constructor and Description |
|---|
Logger(java.lang.String tag) |
| Modifier and Type | Method and Description |
|---|---|
void |
d(java.lang.String msg,
java.lang.Object... args)
Sends a
Log.Level.DEBUG log message. |
void |
e(java.lang.String msg,
java.lang.Object... args)
Sends an
Log.Level.ERROR log message. |
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. |
void |
i(java.lang.String msg,
java.lang.Object... args)
Sends an
Log.Level.INFO log message. |
void |
v(java.lang.String msg,
java.lang.Object... args)
Sends a
Log.Level.VERBOSE log message. |
void |
w(java.lang.String msg,
java.lang.Object... args)
Sends a
Log.Level.WARN log message. |
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. |
void |
wtf(java.lang.String msg,
java.lang.Object... args)
What a Terrible Failure: Report a condition that should never happen.
|
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 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 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 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 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 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 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 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 void wtf(java.lang.String msg,
java.lang.Object... args)
msg - the message you would like loggedargs - the extra arguments for the messagepublic 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 message