A log tool which can be used in android or java, the most important feature is it can print the
logs to multiple place in the same time, such as android shell, console and file, you can
even print the log to the remote server if you want, all of these can be done just within one
calling.
Also, XLog is very flexible, almost every component is replaceable.
How to use in a general way:
1. Initial the log system.
Using one of
XLog#init()
XLog#init(int),
XLog#init(LogConfiguration)
XLog#init(Printer...),
XLog#init(int,Printer...),
XLog#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
android.util.Log, all the methods of
android.util.Log are supported here.
See:
Log#v(String,String),
Log#v(String,String,Throwable)
Log#d(String,String),
Log#d(String,String,Throwable)
Log#i(String,String),
Log#i(String,String,Throwable)
Log#w(String,String),
Log#w(String,String,Throwable)
Log#wtf(String,String),
Log#wtf(String,String,Throwable)
Log#e(String,String),
Log#e(String,String,Throwable)
Log#println(int,String,String)
Log#isLoggable(String,int)
Log#getStackTraceString(Throwable)