Configuring a root registrar using the Java Registration API

How can I customize the behavior of the root logger in the logging api? I don’t want to configure the behavior of each registrar separately, instead it would be very convenient if I had one properties file where I can set the behavior of all registrars.

+3
source share
3 answers

I would suggest using Apache Commons Logging or log4j directly. It is much more comfortable and flexible.

EDIT:

, Vinay Sajip. API, Logger ", ,

private final static Logger logger = Logger.getLogger("");
-8

, java.util.logging (JUL): , Java Almanac. JUL . , .

: Java Almanac, (linkrot ), jschoen. Google .

+3

To get the root logger, use the following:

Logger system = Logger.getLogger("");

Now you can access the root log like any other registrar.

In my case, I was ready to calm down. I managed to do this with the following code:

private static void setLevel(Logger pLogger, Level pLevel) {
    Handler[] handlers = pLogger.getHandlers(); 
    for (Handler h : handlers) {
        h.setLevel(pLevel);
    }
    pLogger.setLevel(pLevel);
}

...

setLevel(system, Level.OFF);

Hope this helps.

+3
source

Source: https://habr.com/ru/post/1716876/


All Articles