Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SLF4J + logback + JBoss 7?

Has anyone got SLF4J / logback to work with JBoss 7?

Previously, I was able to get my app to work in JBoss 5.1 by putting my "logback.groovy" in [server]/conf, and the logback core, classic (0.9.28), and Groovy (1.8.0) JARs in [server]/lib.

For JBoss 7.0.1, I've got the Groovy and logback modules set up OK (the .index files have been created), my EAR's MANIFEST.MF declares dependencies on both modules, and my "logback.groovy" is deployed in my WAR module's WEB-INF/classes, within my EAR. The EAR definitely deploys OK - lights are green...

Despite this, the only logging rules that actually get applied are the standard console/server.log ones set up in "standalone.xml". Yes, I can see my log statements (so SLF4J is working), but my logback rules, appenders, etc. are being ignored. There are no references to either logback or Groovy in any of that logging, so I'm assuming that I've not done enough to trigger logback's loading and finding my script.

There are other things I could try, but it would be good to know if other people have tried this. If they haven't, perhaps that's a sign that I should just throw in my lot with JBoss Logging?

like image 544
Andrew Regan Avatar asked Sep 21 '11 11:09

Andrew Regan


People also ask

Does Logback require slf4j?

Note that logback-classic transitively includes the slf4j-api and logback-core , so only having the logback-classic is enough to setup logback with slf4j. When using Logback with SLF4j, a console appender with DEBUG log level is configured automatically. For custom logback configuration, we need to create logback.

What is Logback?

Logback is a logging framework for Java applications, created as a successor to the popular log4j project.

What is the use of Logback XML?

Logback executes an async appender in a separate thread to decouple the logging overhead from the thread executing your code. Using the async appender is incredibly easy. Refer the appender that should be asynchronously invoked within an <appender> element.


2 Answers

Are you sure logback is active? If logback cannot find a configuration file, i.e. logback.groovy or logback.xml, it will print a warning message on the console. The output should be similar to:

12:49:22,078 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
12:49:22,093 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]
12:49:22,093 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Setting up default configuration.

Do you see any such output on the console? If not, assuming that Jboss 7 is bundled with an slf4j-binding, you are probably already using Jboss logging. (Your calls to the slf4j api are being sent to jboss logging instead of logback.)

The Jboss folks should be contacted about using a logging backend other than jboss-logging.

Digging a little further, I noticed that JAS7 ships with a file called slf4j-jboss-logmanager-1.0.0.GA.jar located under the ./modules/org/slf4j/impl/main/ folder. The contents of this file show that it is definitely an slf4j binding. I do not know how Jboss "modules" work but removing/disabling slf4j-jboss-logmanager is the way to go if you wish logback-classic to be picked up by slf4j.

like image 154
Ceki Avatar answered Sep 28 '22 09:09

Ceki


JBoss AS7 uses the jboss-logmanager. I assume that logback appenders would require a log manger that can handle them. I'm not really sure what would happen if you switched out the log manager.

There is support for custom java.util.logging.Handler's so you could write a wrapper for an appender in a handler. I know it's probably not ideal, but it should work.

I would encourage anyone to use JBoss Logging and not just because I work on it :-) It really does have some nice features, like var-arg log methods which is what drew me to it in the first place. There is also support for i18n logging and messages through interfaces.

Also JBoss Logging is more than just an API. It's a full logging framework. In the next release of JBoss Logging we will offer a way to specify which log manager you would like to use. That might make something like this a bit easier, but I must admit I have not tested in in AS7. If I get the time I will though.

like image 28
James R. Perkins Avatar answered Sep 28 '22 11:09

James R. Perkins