How do I quickly enable or disable file printing
Opened this issue · 1 comments
sfxpamusuo commented
Hi... Good day
I am using your XLog in an app and it has been nice and robust so far
Is there a method I can call to enable or disable file printing?
My use case is this
I have a setting from the backend which determines if I should log to file or not
Currently, whenever I want to log, I check the value of the setting and if it is true, I log
But this causes frequent db calls and if the setting is false, this implementation cant allow the logs be printed to the android logcat console
I wanted an alternate method I could just call to change the printers enabled on runtime
Thank you
elvishew commented
@sfxpamusuo You can wrap the FilePrinter
and control the printing in the println(int logLevel, String tag, String msg)
method,
FilePrinter originFilePrinter = ...;
Printer variableFilePrinter = new Printer() {
void println(int logLevel, String tag, String msg) {
if (settingIsTrue) {
originFilePrinter.println(logLevel, tag, msg);
}
}
}
XLog.init(...variableFilePrinter);