Brendan Long
Brendan Long

Reputation: 54252

SLF4J logs error messages at info level

I'm running into a weird problem. I have a class that used to use Log4j, and I could do something like:

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

And I'd get output like this:

SEVERE: This is a message

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

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

But now it's logging at INFO level:

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

I was expecting this to be logged at ERROR level (SLF4J doesn't seem to have any levels above that).

Any idea what's going on? Is this the default? The application is fairly complicated, so I wouldn't be surprised if this was changed somewhere, but where would I find that to change it back?

I'm using Glassfish, in case that might be related.

Upvotes: 4

Views: 1829

Answers (2)

Will Hartung
Will Hartung

Reputation: 118691

you need to make your SLF4J use the Java Util Logging backend. That's what Glassfish uses internally. Since it's not using that, it's dumping to the console, and GF reports everything on the console as INFO.

So hook up the JUL adapter and you should be all good.

Upvotes: 4

mantrid
mantrid

Reputation: 2840

without configuration listing for logging it's only a guess. but I think the logging framework is probably misconfigured. slf4j logs at ERROR level:

ERROR com.mycompany.MyClass - This is a message

then this output is sent into console, which is redirected into general log file at INFO level by glassfish.

previous setup probably used glassfish logging directly inheriting its configuration. after switching to slf4j no config was found so everything is sent to console and then to server.log

Upvotes: 1

Related Questions