SLF4J logs error messages at the information level

I got confused by a weird problem. I have a class that used Log4j, and I could do something like:

LOGGER.log(Level.SEVERE, "This is a message"); 

And I get the output as follows:

SEVERE: This message

I replaced it with the SLF4J logger for consistency with the rest of the application:

 LOGGER.error("This is a message."); 

But now it is registered at the INFO level:

INFO: 2012-01-23 16: 50: 43,306 [http-thread-pool-8080 (3)] ERROR com.mycompany.MyClass is a message

I expected this to be registered at the ERROR level (SLF4J does not seem to have levels above this).

Any idea what is going on? Is this the default value? The application is quite complicated, so I won’t be surprised if this has changed somewhere, but where can I find it to change it?

I use Glassfish if this could be related.

+4
source share
2 answers

you need your SLF4J to use the Java Util Logging backend. What Glassfish uses internally. Since it does not use this, it is reset to the console, and GF reports everything on the console as INFO.

So plug in the JUL adapter and everything should be fine.

+4
source

without a configuration list to register in it only assumptions. but I think the logging structure is probably misconfigured. slf4j logs at the ERROR level:

 ERROR com.mycompany.MyClass - This is a message 

then this output is sent to the console, which is redirected to the general log file at the INFO level through a glass chip.

the previous setup probably used glass-based logging, directly inheriting its configuration. after switching to slf4j no config was found, so everything was sent to the console, and then to server.log

+1
source

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


All Articles