-
public class LogUtility class for Android libraries, that simplifies the use of android.util.Log by improving the call to all log methods by supplying arguments as parameters
{@code '%s'}instead of creating a string. This avoids useless memory allocations when not requested: the{@code StringBuilder}itself, the bufferand the{@code 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:
- Automatic TAG corresponding to the caller class name.
- Runtime log level without the need of props file (useful for libraries).
- Method name with line number.
Use 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);
-
-
Method Summary
Modifier and Type Method Description static voidsetLevel(int level)static voidlogMethodName(boolean method, boolean line)Allows to log method name and line number from where the log is called. static booleanisVerboseEnabled()static booleanisDebugEnabled()static booleanisInfoEnabled()static booleanisWarnEnabled()static booleanisErrorEnabled()static voidv(String msg, Array<Object> args)Sends a VERBOSE log message. static voidd(String msg, Array<Object> args)Sends a DEBUG log message. static voidi(String msg, Array<Object> args)Sends an INFO log message. static voidiTag(String tag, String msg, Array<Object> args)As i but with custom tag for one call only. static voidw(String msg, Array<Object> args)Sends a WARN log message. static voidw(Throwable t, String msg, Array<Object> args)Sends a WARN log message with the Exception at the end of the message. static voide(String msg, Array<Object> args)Sends an ERROR log message. static voide(Throwable t, String msg, Array<Object> args)Sends an ERROR log message with the Exception at the end of the message. static voidwtf(String msg, Array<Object> args)What a Terrible Failure: Report a condition that should never happen. static voidwtf(Throwable t, String msg, Array<Object> args)What a Terrible Failure: Report a condition that should never happen with the Exceptionat the end of the message. static voiduseTag(@Nullable() String customTag)Sets a general static custom tag for ALL log calls. -
-
Method Detail
-
setLevel
static void setLevel(int level)
-
logMethodName
static void logMethodName(boolean method, boolean line)
Allows to log method name and line number from where the log is called.
- With method name:
Note: Line number needs method name enabled.{@code [method] msg}.- With line number:{@code [method:line] msg}.- Parameters:
method- true to print method name at the beginning of the message, false otherwiseline- true to print line number after the method name, false otherwise
-
isVerboseEnabled
static boolean isVerboseEnabled()
-
isDebugEnabled
static boolean isDebugEnabled()
-
isInfoEnabled
static boolean isInfoEnabled()
-
isWarnEnabled
static boolean isWarnEnabled()
-
isErrorEnabled
static boolean isErrorEnabled()
-
v
static void v(String msg, Array<Object> args)
Sends a VERBOSE log message.
- Parameters:
msg- the message you would like loggedargs- the extra arguments for the message
-
d
static void d(String msg, Array<Object> args)
Sends a DEBUG log message.
- Parameters:
msg- the message you would like loggedargs- the extra arguments for the message
-
i
static void i(String msg, Array<Object> args)
Sends an INFO log message.
- Parameters:
msg- the message you would like loggedargs- the extra arguments for the message
-
iTag
static void iTag(String tag, String msg, Array<Object> args)
As i but with custom tag for one call only.
- Parameters:
tag- custom tag, used to identify the source of a log messagemsg- the message you would like loggedargs- the extra arguments for the message
-
w
static void w(String msg, Array<Object> args)
Sends a WARN log message.
- Parameters:
msg- the message you would like loggedargs- the extra arguments for the message
-
w
static void w(Throwable t, String msg, Array<Object> args)
Sends a WARN log message with the Exception at the end of the message.
- Parameters:
t- The exception to logmsg- the message you would like loggedargs- the extra arguments for the message
-
e
static void e(String msg, Array<Object> args)
Sends an ERROR log message.
- Parameters:
msg- the message you would like loggedargs- the extra arguments for the message
-
e
static void e(Throwable t, String msg, Array<Object> args)
Sends an ERROR log message with the Exception at the end of the message.
- Parameters:
t- The exception to logmsg- the message you would like loggedargs- the extra arguments for the message
-
wtf
static void wtf(String msg, Array<Object> args)
What a Terrible Failure: Report a condition that should never happen.
- Parameters:
msg- the message you would like loggedargs- the extra arguments for the message
-
wtf
static void wtf(Throwable t, String msg, Array<Object> args)
What a Terrible Failure: Report a condition that should never happen with the Exceptionat the end of the message.
- Parameters:
t- The exception to logmsg- the message you would like loggedargs- the extra arguments for the message
-
-
-
-