Java logging java dot util dot logging - nimrody/knowledgebase GitHub Wiki
Java.util.logging configuration
-
Add JVM options to select configuration file (the following shows setting the options when using the Gradle Application plugin)
export JAVA_OPTS=-Djava.util.logging.config.file=$HOME/logging.properties
-
And the
logging.properties
file:default logging level
.level= INFO
Limit the messages that are printed on the console to INFO and above.
java.util.logging.ConsoleHandler.level = INFO
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
handlers=java.util.logging.ConsoleHandler
java.util.logging.SimpleFormatter.format=%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$-6s %2$s %5$s%6$s%n
Or programmatically
static {
System.setProperty("java.util.logging.SimpleFormatter.format", "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS %4$s %2$s %5$s%6$s%n");
}
-
Disable AWS Apache Commons logging
static { java.util.logging.Logger.getLogger("com.amazonaws.http.AmazonHttpClient").setLevel(Level.WARNING); }
-
Set alternative logger and remove default
if (enableJsonLogs) { LogManager.getLogManager().reset(); java.util.logging.Logger julLogger = java.util.logging.Logger.getLogger(""); LogFormatter formatter = new LogFormatter(); ConsoleHandler handler = new ConsoleHandler(); handler.setFormatter(formatter); julLogger.addHandler(handler); }