xLog
xLog copied to clipboard
保存日志到本地文件,可以记录进程id和进程名吗?
apk做了多进程,看本地日志文件的时候,只能看到线程id,无法看到进程id和进程名,不太方便。谢谢
For performance, load process info only once.
static String procName = loadProcessName();
static int pid = loadPid();
You can add an Interceptor
when initializing xLog, and append procName
and pid
to log message
LogConfiguration config = new LogConfiguration.Builder()
.addInterceptor(log -> {
log.msg = log.msg + <process name and ID>;
return log;
})
...
XLog.init(config...)
Or, if you want the process info displayed together with thread info, you can customize a ThreadFormatter
LogConfiguration config = new LogConfiguration.Builder()
.enableThreadInfo()
.threadFormatter(thread -> {
return "Process" + pid + ":" + procName + " Thread:" + thread.getName();
})
...
XLog.init(config...)
Hope this help you!
Thanks. I read the source of xlog find I can customize a ThreadFormatter to append msg to log. the expandability of xlog is so great! Thanks for you!
But I don't understand why design tag for global in default.In my case I need tag for current class. I found that use Xlog.tag(xx) to custom tag,but invoke xlog.tag(xxx) will create a new Logger object in every times, For performance, I think this is not good ,this is my views, hoping your answer!
But I don't understand why design tag for global in default.In my case I need tag for current class. I found that use Xlog.tag(xx) to custom tag,but invoke xlog.tag(xxx) will create a new Logger object in every times, For performance, I think this is not good ,this is my views, hoping your answer!
Currently, if you want to use different tags in different classes, you can keep a Logger
with a custom tag in each class, and use this Logger.*
instead of using XLog.*
directly.
怎么抓取别的进程的日志啊?另外,我想在不同的类中打印日志的时候,添加对应类名作为tag 可以实现么?