Direkt zum Hauptinhalt

LOGGING

Uhm yeh stuff went south with log4j. And some Libs like JDA uses SLF4J and need a loggin backend.

here is a small guide on of to use the java own Logging backend java.util.loggin

logging.properties

load file

is a file which specifies on how stuff gets logged, similar to log4j

you have several ways to tell java where this file is:

  1. default config

i mean obviously ... usualy located at JAVA_HOME/jre/lib/logging.properties or /PATH_TO_JDK/conf/logging.properties

  1. use a falg on starting you application

tbh i forgot the flag but ... its there!

  1. use the LoggerManager

load yout configuration here as example from /main/resources/

LogManager loggerMG = java.util.logging.LogManager.getLogManager();
loggerMG.readConfiguration(MissingIDent.class.getClassLoader().getResourceAsStream("logging.properties"));
  1. Set static JVM Properties

well that possible too but ... again i forgot how to ...

configurate

following website helped me to understand what you could configurate:

  1. jenkov.com (general config)
  2. oracle.com SimpleFormatter (docs for formating)
  3. oracle.com Formatter (docs for formating)
  4. geeksforgeeks.org (some examples)

i endet up with following config:

handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler

java.util.logging.FileHandler.level=ALL
java.util.logging.FileHandler.limit=10485760
java.util.logging.FileHandler.count=2
java.util.logging.FileHandler.append=true
java.util.logging.FileHandler.pattern=FOOBAABAZ%g.log
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

java.util.logging.ConsoleHandler.level=ALL
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter

java.util.logging.SimpleFormatter.format=[%1$TF-%1$TT][%2$s][%4$s] : %5$s %6$s %n

FOO.BAA.BAZ.level=WARNING