I'm using a library that logs a bunch of stuff that I don't want to log. It's using java.util.logging
.
I also don't want to completely disable its logging since some of its logs are useful. Since the unwanted lines are logged only when I run a certain task, if there was a global way of disabling and enabling logging it would solve my problem.
Ideally something like:
disableLogging();
taskThatMakesUnnecessaryLogs();
enableLogging();
The JDK Logging Adapter is a custom implementation of java. util. logging. LogManager that uses Log4j.
For a global impact you can use LogManager.reset()
as your call to disable logging and to re-enable logging you can LogManager.readConfiguration()
. However, there are some major flaws in what actually gets reloaded. The newer JDK9 method LogManager.updateConfiguration should be used instead.
If you know the logger name you can edit your logging.properties to modify the level of that offending logger or create a filter.
From code you can locate the logger and change it's level to OFF
or something higher than the log messages you are seeing.
final Logger chatty = Logger.getLogger("somelogger");
final Level oldLevel = chatty.getLevel();
chatty.setLevel(Level.OFF);
try {
taskThatMakesUnnecessaryLogs();
} finally {
chatty.setLevel(oldLevel);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With