reschifl
reschifl

Reputation: 387

JBoss AS7: logging with logback

I would like to use slf4j+logback for logging on an JBossAS7.

Additionaly I have to solve the following requirements:

What I know now, is that JBoss uses its own logging layer. For architectural reasons, I can not use this. I would like to stick with only SLF4J as Logging-API and Logback as framework.

I would be happy to get some hints, how this could be solved.

Regards,

Lars

Upvotes: 3

Views: 3446

Answers (2)

skiphoppy
skiphoppy

Reputation: 102723

I am pretty sure that you can use slf4j+logback for your own applications within JBoss and completely bypass its logging. JBoss will continue logging all of its own log messages to its own logs, but your software will not connect to jboss-logging at all and will have its own logs. I have tried this under JBoss 6; we have not yet tried JBoss 7, so things may be different there, but I doubt it. Just make sure slf4j and logback jars are in your applications' classpaths, and you should be good.

If you search through the System properties available to you, you will find some jboss.* properties that may be useful in your logback configuration for finding a place to put your log files.

Personally, I wish JBoss would switch to using slf4j.

Upvotes: 1

James R. Perkins
James R. Perkins

Reputation: 17770

Lars, The only way I can think of to do this would be to write a custom handler. While it's not very well documented at the moment, you can create custom java.util.logging.Handler's. You could write a wrapper in a sense around around the logback's configuration. I think they have a BasicConfigurator or something like that.

You register a custom handler like so:

<custom-handler name="logbackHandler" class="org.jboss.LogbackHandler" module="org.jboss.logback">
   <level name="DEBUG"/>
   <properties>
       <property name="nameOfASetterMethod" value="the value to set" />
   </properties>
</custom-handler>

<root-logger>
    <level name="INFO"/>
    <handlers>
        <handler name="CONSOLE"/>
        <handler name="FILE"/>
        <handler name="logbackHandler"/>
    </handlers>
</root-logger>

That said there is probably no real need to do that. The application server logger will log the messages even if you are logging through a different façade. You can set-up different file handlers if you want to write to your own files.

I realize logging in JBoss AS7 could really use some better documentation. I do plan on updating that when I find the time :-) And really I just need to make the time.

Upvotes: 1

Related Questions