Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure the root logger with java logging API

Tags:

java

logging

how can I configure the behaviour of the root logger in the logging api? I don't want to configure the behaviour of each logger separately, instead it would be very convenient if I have a single property file where I can set the behaviour of all loggers.

like image 267
Sebastian Müller Avatar asked Sep 04 '09 07:09

Sebastian Müller


1 Answers

Use the following to get the root logger:

Logger system = Logger.getLogger("");

You can now access the root logger as any other logger.

In my case I was willing to make it quiet. I succeeded to do it 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.

like image 84
Algiz Avatar answered Nov 10 '22 14:11

Algiz