@ThreadSafe public final class Lumberjack extends Object
Going beyond Log, this class automatically generates a log tag, prefixes
log
messages with the current thread name, prefixes log messages with the current class and method
name, and handles String formats with ease. When given certain objects as String formats, such
as
Cursor, Array, Intent, or Bundle, this class knows how to stringify them in a useful manner
instead of using the native toString() methods of these objects.
Prior to calling any of the logging methods of this class, clients should call
init(Context). Typically this call is made from either
Application.onCreate() or ContentProvider.onCreate().
After init(Context) is called, the log tag is automatically generated by lowercasing
the
app's name and replacing whitespace with hyphens. Clients may override this behavior, by adding
the string resource com_twofortyfouram_log_tag to set an explicit log tag.
Additional debug behaviors may be enabled by providing the boolean resource
com_twofortyfouram_log_is_debug. Setting that resource to true will enable
StrictMode warnings, as well as enable logging for the Fragment and Loader frameworks.
Because logging in production code is literally dead wood, clients should strip out logging
statements at compile time with ProGuard/DexGuard, with the exception of the
always(String, Object...). The configuration would look like the following, which is
already included in the AAR file for the spackle library:
-assumenosideeffects public class com.twofortyfouram.log.Lumberjack {
public static *** v(...);
public static *** d(...);
public static *** i(...);
public static *** w(...);
public static *** e(...);
}
| Modifier and Type | Method and Description |
|---|---|
static void |
always(String msg,
Object... args)
Always log a message, because this method is not stripped out by ProGuard/DexGuard by
default.
|
static void |
d(String msg,
Object... args)
Log a message.
|
static void |
e(String msg,
Object... args)
Log a message.
|
static String |
formatMessage(String msg,
Object... args)
Helper for varargs.
|
static void |
i(String msg,
Object... args)
Log a message.
|
static void |
init(Context context)
Initializes logging.
|
static void |
v(String msg,
Object... args)
Log a message.
|
static void |
w(String msg,
Object... args)
Log a message.
|
public static void init(Context context)
This normally should be called once in Application.onCreate(). (It may
also need to be called from ContentProvider.onCreate() due to the
fact that ContentProvider objects are created before Application objects on some Android
platform versions).
context - Application context.public static void always(String msg, Object... args)
Log.INFO logging
level.
This method should be used with discretion, as log statements will be preserved in release builds. DO NOT log sensitive information, such as password, access tokens, location information, or other private details that shouldn't be readable by other applications.
msg - message to log.args - to format into the String.public static void v(String msg, Object... args)
msg - message to log. This message is expected to be a format string if varargs are
passed.args - optional arguments to be formatted into msg.public static void d(String msg, Object... args)
msg - message to log. This message is expected to be a format string if varargs are
passed.args - optional arguments to be formatted into msg.public static void i(String msg, Object... args)
msg - message to log. This message is expected to be a format string if varargs are
passed.args - optional arguments to be formatted into msg.public static void w(String msg, Object... args)
msg - message to log. This message is expected to be a format string if varargs are
passed.args - optional arguments to be formatted into msg.public static void e(String msg, Object... args)
msg - message to log. This message is expected to be a format string if varargs are
passed.args - optional arguments to be formatted into msg.