I want to use java.util.logging on Android. I want to configure the logging system with logging.properties. But how can I tell Android using the specific configure file? For
Here is modified answer of Christian Bauer
If somewhere in any third party lib you will see something like this:
final public class AnyClass {
private static final Logger logger = Logger.getLogger(AnyClass.class.getName());
...
if (logger.isLoggable(Level.FINE)) {
logger.fine("any log event");
}
...
}
Add to your code this after creating first instance of AnyClass.class:
SetupLogger.setup(Arrays.asList(
new Pair<>(AnyClass.class.getName(), Level.FINEST),//AnyClass.class.getName() is because instance `logger` has his name
new Pair<>(AnyOther.class.getName(), Level.FINEST)
));
SetupLogger .class
public class SetupLogger {
static public void setup(List> loggerNames) {
// suppress the logging output to the console
AndroidLoggingHandler rootHandler = new AndroidLoggingHandler();
AndroidLoggingHandler.reset(rootHandler );
for (Pair pair : loggerNames) {
Logger logger = Logger.getLogger(pair.first);
logger.setLevel(pair.second);
}
}
}