public class XLog
extends java.lang.Object
How to use in a general way:
1. Initial the log system.
Using one of
init()
init(int),
init(LogConfiguration)
init(Printer...),
init(int, Printer...),
init(LogConfiguration, Printer...),
that will setup a Logger for a global usage.
If you want to use a customized configuration instead of the global one to log something, you can
start a customization logging.
For android, a best place to do the initialization is Application.onCreate().
2. Start to log.
v(String, Object...), v(String) and v(String, Throwable) are for
logging a LogLevel.INFO message.
d(String, Object...), d(String) and d(String, Throwable) are for
logging a LogLevel.DEBUG message.
i(String, Object...), i(String) and i(String, Throwable) are for
logging a LogLevel.INFO message.
w(String, Object...), w(String) and w(String, Throwable) are for
logging a LogLevel.WARN message.
e(String, Object...), e(String) and e(String, Throwable) are for
logging a LogLevel.ERROR message.
log(int, String, Object...), log(int, String) and
log(int, String, Throwable) are for logging a specific level message.
json(String) is for logging a LogLevel.DEBUG JSON string.
xml(String) is for logging a LogLevel.DEBUG XML string.
Also, you can directly log any object with specific log level, like v(Object),
and any object array with specific log level, like v(Object[]).
How to use in a dynamically customizing way after initializing the log system:
1. Start a customization.
Call any of
logLevel(int)
tag(String),
t(),
nt(),
st(int),
nst(),
b(),
nb(),
jsonFormatter(JsonFormatter),
xmlFormatter(XmlFormatter),
threadFormatter(ThreadFormatter),
stackTraceFormatter(StackTraceFormatter),
throwableFormatter(ThrowableFormatter)
borderFormatter(BorderFormatter)
addObjectFormatter(Class, ObjectFormatter)
addInterceptor(Interceptor)
printers(Printer...),
it will return a Logger.Builder object.
2. Finish the customization.
Continue to setup other fields of the returned Logger.Builder.
3. Build a dynamically generated Logger.
Call the Logger.Builder.build() of the returned Logger.Builder.
4. Start to log.
The logging methods of a Logger is completely same as that ones in XLog.
As a convenience, you can ignore the step 3, just call the logging methods of
Logger.Builder, it will automatically build a Logger and call the target
logging method.
Compatibility:
In order to be compatible with Log, all the methods of
Log are supported here.
See:
XLog.Log.v(String, String), XLog.Log.v(String, String, Throwable)
XLog.Log.d(String, String), XLog.Log.d(String, String, Throwable)
XLog.Log.i(String, String), XLog.Log.i(String, String, Throwable)
XLog.Log.w(String, String), XLog.Log.w(String, String, Throwable)
XLog.Log.wtf(String, String), XLog.Log.wtf(String, String, Throwable)
XLog.Log.e(String, String), XLog.Log.e(String, String, Throwable)
XLog.Log.println(int, String, String)
XLog.Log.isLoggable(String, int)
XLog.Log.getStackTraceString(Throwable)
| Modifier and Type | Class and Description |
|---|---|
static class |
XLog.Log
Deprecated.
please use
XLog instead |
| Modifier and Type | Method and Description |
|---|---|
static Logger.Builder |
addInterceptor(Interceptor interceptor)
Start to customize a
Logger and add an interceptor. |
static <T> Logger.Builder |
addObjectFormatter(java.lang.Class<T> objectClass,
ObjectFormatter<? super T> objectFormatter)
Start to customize a
Logger and add an object formatter for specific class of object. |
static Logger.Builder |
b()
Start to customize a
Logger and enable border. |
static Logger.Builder |
borderFormatter(BorderFormatter borderFormatter)
Start to customize a
Logger and set the BorderFormatter. |
static void |
d(java.lang.Object object)
Log an object with level
LogLevel.DEBUG. |
static void |
d(java.lang.Object[] array)
Log an array with level
LogLevel.DEBUG. |
static void |
d(java.lang.String msg)
Log a message with level
LogLevel.DEBUG. |
static void |
d(java.lang.String format,
java.lang.Object... args)
Log a message with level
LogLevel.DEBUG. |
static void |
d(java.lang.String msg,
java.lang.Throwable tr)
Log a message and a throwable with level
LogLevel.DEBUG. |
static void |
e(java.lang.Object object)
Log an object with level
LogLevel.ERROR. |
static void |
e(java.lang.Object[] array)
Log an array with level
LogLevel.ERROR. |
static void |
e(java.lang.String msg)
Log a message with level
LogLevel.ERROR. |
static void |
e(java.lang.String format,
java.lang.Object... args)
Log a message with level
LogLevel.ERROR. |
static void |
e(java.lang.String msg,
java.lang.Throwable tr)
Log a message and a throwable with level
LogLevel.ERROR. |
static void |
i(java.lang.Object object)
Log an object with level
LogLevel.INFO. |
static void |
i(java.lang.Object[] array)
Log an array with level
LogLevel.INFO. |
static void |
i(java.lang.String msg)
Log a message with level
LogLevel.INFO. |
static void |
i(java.lang.String format,
java.lang.Object... args)
Log a message with level
LogLevel.INFO. |
static void |
i(java.lang.String msg,
java.lang.Throwable tr)
Log a message and a throwable with level
LogLevel.INFO. |
static void |
init()
Initialize log system, should be called only once.
|
static void |
init(int logLevel)
Initialize log system, should be called only once.
|
static void |
init(int logLevel,
LogConfiguration logConfiguration)
Deprecated.
the log level is part of log configuration now, use
init(LogConfiguration)
instead, since 1.3.0 |
static void |
init(int logLevel,
LogConfiguration logConfiguration,
Printer... printers)
Deprecated.
the log level is part of log configuration now,
use
init(LogConfiguration, Printer...) instead, since 1.3.0 |
static void |
init(int logLevel,
Printer... printers)
Initialize log system, should be called only once.
|
static void |
init(LogConfiguration logConfiguration)
Initialize log system, should be called only once.
|
static void |
init(LogConfiguration logConfiguration,
Printer... printers)
Initialize log system, should be called only once.
|
static void |
init(Printer... printers)
Initialize log system, should be called only once.
|
static void |
json(java.lang.String json)
Log a JSON string, with level
LogLevel.DEBUG by default. |
static Logger.Builder |
jsonFormatter(JsonFormatter jsonFormatter)
Start to customize a
Logger and set the JsonFormatter. |
static void |
log(int logLevel,
java.lang.Object object)
Log an object with specific log level.
|
static void |
log(int logLevel,
java.lang.Object[] array)
Log an array with specific log level.
|
static void |
log(int logLevel,
java.lang.String msg)
Log a message with specific log level.
|
static void |
log(int logLevel,
java.lang.String format,
java.lang.Object... args)
Log a message with specific log level.
|
static void |
log(int logLevel,
java.lang.String msg,
java.lang.Throwable tr)
Log a message and a throwable with specific log level.
|
static Logger.Builder |
logLevel(int logLevel)
Start to customize a
Logger and set the log level. |
static Logger.Builder |
nb()
Start to customize a
Logger and disable border. |
static Logger.Builder |
nst()
Start to customize a
Logger and disable stack trace. |
static Logger.Builder |
nt()
Start to customize a
Logger and disable thread info. |
static Logger.Builder |
printers(Printer... printers)
|
static Logger.Builder |
st(int depth)
Start to customize a
Logger and enable stack trace. |
static Logger.Builder |
st(java.lang.String stackTraceOrigin,
int depth)
Start to customize a
Logger and enable stack trace. |
static Logger.Builder |
stackTraceFormatter(StackTraceFormatter stackTraceFormatter)
Start to customize a
Logger and set the StackTraceFormatter. |
static Logger.Builder |
t()
Start to customize a
Logger and enable thread info. |
static Logger.Builder |
tag(java.lang.String tag)
Start to customize a
Logger and set the tag. |
static Logger.Builder |
threadFormatter(ThreadFormatter threadFormatter)
Start to customize a
Logger and set the ThreadFormatter. |
static Logger.Builder |
throwableFormatter(ThrowableFormatter throwableFormatter)
Start to customize a
Logger and set the ThrowableFormatter. |
static void |
v(java.lang.Object object)
Log an object with level
LogLevel.VERBOSE. |
static void |
v(java.lang.Object[] array)
Log an array with level
LogLevel.VERBOSE. |
static void |
v(java.lang.String msg)
Log a message with level
LogLevel.VERBOSE. |
static void |
v(java.lang.String format,
java.lang.Object... args)
Log a message with level
LogLevel.VERBOSE. |
static void |
v(java.lang.String msg,
java.lang.Throwable tr)
Log a message and a throwable with level
LogLevel.VERBOSE. |
static void |
w(java.lang.Object object)
Log an object with level
LogLevel.WARN. |
static void |
w(java.lang.Object[] array)
Log an array with level
LogLevel.WARN. |
static void |
w(java.lang.String msg)
Log a message with level
LogLevel.WARN. |
static void |
w(java.lang.String format,
java.lang.Object... args)
Log a message with level
LogLevel.WARN. |
static void |
w(java.lang.String msg,
java.lang.Throwable tr)
Log a message and a throwable with level
LogLevel.WARN. |
static void |
xml(java.lang.String xml)
Log a XML string, with level
LogLevel.DEBUG by default. |
static Logger.Builder |
xmlFormatter(XmlFormatter xmlFormatter)
Start to customize a
Logger and set the XmlFormatter. |
public static void init()
public static void init(int logLevel)
logLevel - the log level, logs with a lower level than which would not be printed@Deprecated
public static void init(int logLevel,
LogConfiguration logConfiguration)
init(LogConfiguration)
instead, since 1.3.0logLevel - the log level, logs with a lower level than which would not be printedlogConfiguration - the log configurationpublic static void init(LogConfiguration logConfiguration)
logConfiguration - the log configurationpublic static void init(Printer... printers)
printers - the printers, each log would be printed by all of the printerspublic static void init(int logLevel,
Printer... printers)
logLevel - the log level, logs with a lower level than which would not be printedprinters - the printers, each log would be printed by all of the printers@Deprecated
public static void init(int logLevel,
LogConfiguration logConfiguration,
Printer... printers)
init(LogConfiguration, Printer...) instead, since 1.3.0logLevel - the log level, logs with a lower level than which would not be printedlogConfiguration - the log configurationprinters - the printers, each log would be printed by all of the printerspublic static void init(LogConfiguration logConfiguration, Printer... printers)
logConfiguration - the log configurationprinters - the printers, each log would be printed by all of the printerspublic static Logger.Builder logLevel(int logLevel)
Logger and set the log level.logLevel - the log level to customizeLogger.Builder to build the Loggerpublic static Logger.Builder tag(java.lang.String tag)
Logger and set the tag.tag - the tag to customizeLogger.Builder to build the Loggerpublic static Logger.Builder t()
Logger and enable thread info.Logger.Builder to build the Loggerpublic static Logger.Builder nt()
Logger and disable thread info.Logger.Builder to build the Loggerpublic static Logger.Builder st(int depth)
Logger and enable stack trace.depth - the number of stack trace elements we should log, 0 if no limitationLogger.Builder to build the Loggerpublic static Logger.Builder st(java.lang.String stackTraceOrigin, int depth)
Logger and enable stack trace.stackTraceOrigin - the origin of stack trace elements from which we should NOT log,
it can be a package name like "com.elvishew.xlog", a class name
like "com.yourdomain.logWrapper", or something else between
package name and class name, like "com.yourdomain.".
It is mostly used when you are using a logger wrapperdepth - the number of stack trace elements we should log, 0 if no limitationLogger.Builder to build the Loggerpublic static Logger.Builder nst()
Logger and disable stack trace.Logger.Builder to build the Loggerpublic static Logger.Builder b()
Logger and enable border.Logger.Builder to build the Loggerpublic static Logger.Builder nb()
Logger and disable border.Logger.Builder to build the Loggerpublic static Logger.Builder jsonFormatter(JsonFormatter jsonFormatter)
Logger and set the JsonFormatter.jsonFormatter - the JsonFormatter to customizeLogger.Builder to build the Loggerpublic static Logger.Builder xmlFormatter(XmlFormatter xmlFormatter)
Logger and set the XmlFormatter.xmlFormatter - the XmlFormatter to customizeLogger.Builder to build the Loggerpublic static Logger.Builder throwableFormatter(ThrowableFormatter throwableFormatter)
Logger and set the ThrowableFormatter.throwableFormatter - the ThrowableFormatter to customizeLogger.Builder to build the Loggerpublic static Logger.Builder threadFormatter(ThreadFormatter threadFormatter)
Logger and set the ThreadFormatter.threadFormatter - the ThreadFormatter to customizeLogger.Builder to build the Loggerpublic static Logger.Builder stackTraceFormatter(StackTraceFormatter stackTraceFormatter)
Logger and set the StackTraceFormatter.stackTraceFormatter - the StackTraceFormatter to customizeLogger.Builder to build the Loggerpublic static Logger.Builder borderFormatter(BorderFormatter borderFormatter)
Logger and set the BorderFormatter.borderFormatter - the BorderFormatter to customizeLogger.Builder to build the Loggerpublic static <T> Logger.Builder addObjectFormatter(java.lang.Class<T> objectClass, ObjectFormatter<? super T> objectFormatter)
Logger and add an object formatter for specific class of object.T - the type of objectobjectClass - the class of objectobjectFormatter - the object formatter to addLogger.Builder to build the Loggerpublic static Logger.Builder addInterceptor(Interceptor interceptor)
Logger and add an interceptor.interceptor - the interceptor to addLogger.Builder to build the Loggerpublic static Logger.Builder printers(Printer... printers)
printers - the Printer array to customizeLogger.Builder to build the Loggerpublic static void v(java.lang.Object object)
LogLevel.VERBOSE.object - the object to logLogConfiguration.Builder.addObjectFormatter(Class, ObjectFormatter)public static void v(java.lang.Object[] array)
LogLevel.VERBOSE.array - the array to logpublic static void v(java.lang.String format,
java.lang.Object... args)
LogLevel.VERBOSE.format - the format of the message to logargs - the arguments of the message to logpublic static void v(java.lang.String msg)
LogLevel.VERBOSE.msg - the message to logpublic static void v(java.lang.String msg,
java.lang.Throwable tr)
LogLevel.VERBOSE.msg - the message to logtr - the throwable to be logpublic static void d(java.lang.Object object)
LogLevel.DEBUG.object - the object to logLogConfiguration.Builder.addObjectFormatter(Class, ObjectFormatter)public static void d(java.lang.Object[] array)
LogLevel.DEBUG.array - the array to logpublic static void d(java.lang.String format,
java.lang.Object... args)
LogLevel.DEBUG.format - the format of the message to logargs - the arguments of the message to logpublic static void d(java.lang.String msg)
LogLevel.DEBUG.msg - the message to logpublic static void d(java.lang.String msg,
java.lang.Throwable tr)
LogLevel.DEBUG.msg - the message to logtr - the throwable to be logpublic static void i(java.lang.Object object)
LogLevel.INFO.object - the object to logLogConfiguration.Builder.addObjectFormatter(Class, ObjectFormatter)public static void i(java.lang.Object[] array)
LogLevel.INFO.array - the array to logpublic static void i(java.lang.String format,
java.lang.Object... args)
LogLevel.INFO.format - the format of the message to logargs - the arguments of the message to logpublic static void i(java.lang.String msg)
LogLevel.INFO.msg - the message to logpublic static void i(java.lang.String msg,
java.lang.Throwable tr)
LogLevel.INFO.msg - the message to logtr - the throwable to be logpublic static void w(java.lang.Object object)
LogLevel.WARN.object - the object to logLogConfiguration.Builder.addObjectFormatter(Class, ObjectFormatter)public static void w(java.lang.Object[] array)
LogLevel.WARN.array - the array to logpublic static void w(java.lang.String format,
java.lang.Object... args)
LogLevel.WARN.format - the format of the message to logargs - the arguments of the message to logpublic static void w(java.lang.String msg)
LogLevel.WARN.msg - the message to logpublic static void w(java.lang.String msg,
java.lang.Throwable tr)
LogLevel.WARN.msg - the message to logtr - the throwable to be logpublic static void e(java.lang.Object object)
LogLevel.ERROR.object - the object to logLogConfiguration.Builder.addObjectFormatter(Class, ObjectFormatter)public static void e(java.lang.Object[] array)
LogLevel.ERROR.array - the array to logpublic static void e(java.lang.String format,
java.lang.Object... args)
LogLevel.ERROR.format - the format of the message to logargs - the arguments of the message to logpublic static void e(java.lang.String msg)
LogLevel.ERROR.msg - the message to logpublic static void e(java.lang.String msg,
java.lang.Throwable tr)
LogLevel.ERROR.msg - the message to logtr - the throwable to be logpublic static void log(int logLevel,
java.lang.Object object)
logLevel - the specific log levelobject - the object to logLogConfiguration.Builder.addObjectFormatter(Class, ObjectFormatter)public static void log(int logLevel,
java.lang.Object[] array)
logLevel - the specific log levelarray - the array to logpublic static void log(int logLevel,
java.lang.String format,
java.lang.Object... args)
logLevel - the specific log levelformat - the format of the message to logargs - the arguments of the message to logpublic static void log(int logLevel,
java.lang.String msg)
logLevel - the specific log levelmsg - the message to logpublic static void log(int logLevel,
java.lang.String msg,
java.lang.Throwable tr)
logLevel - the specific log levelmsg - the message to logtr - the throwable to be logpublic static void json(java.lang.String json)
LogLevel.DEBUG by default.json - the JSON string to logpublic static void xml(java.lang.String xml)
LogLevel.DEBUG by default.xml - the XML string to log