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:

    default config

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

      use a falg on starting you application

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

        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"));
        
          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:

            jenkov.com (general config) oracle.com SimpleFormatter (docs for formating) oracle.com Formatter (docs for formating) 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