3

我想使用 slf4j+logback 来登录 JBossAS7。

另外,我必须解决以下要求:

  • 我需要在多个部署的应用程序/EAR 中共享一个 logback 配置/上下文
  • 我需要在运行时更改 logback 配置而不重新部署/重新启动 EAR
  • 使(尽可能)JBoss 服务器的日志条目在我的日志配置中可见(例如部署日志等...)

我现在知道的是,JBoss 使用自己的日志记录层。由于架构原因,我不能使用它。我想只使用 SLF4J 作为 Logging-API 和 Logback 作为框架。

我很乐意得到一些提示,如何解决这个问题。

问候,

拉斯

4

2 回答 2

1

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.

于 2011-10-20T16:33:38.890 回答
1

我很确定你可以在 JBoss 中为你自己的应用程序使用 slf4j+logback 并完全绕过它的日志记录。JBoss 将继续将它自己的所有日志消息记录到它自己的日志中,但是你的软件根本不会连接到 jboss-logging 并且会有它自己的日志。我在 JBoss 6 下试过这个;我们还没有尝试过 JBoss 7,所以那里的情况可能会有所不同,但我对此表示怀疑。只要确保 slf4j 和 logback jars 在你的应用程序的类路径中,你应该很好。

如果您搜索可用的系统属性,您会发现一些 jboss.* 属性,这些属性可能在您的 logback 配置中用于查找放置日志文件的位置。

就个人而言,我希望 JBoss 能改用 slf4j。

于 2012-12-06T13:58:41.380 回答