java SLF4J + logback + JBoss 7?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7499014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SLF4J + logback + JBoss 7?
提问by Andrew Regan
Has anyone got SLF4J / logback to work with JBoss 7?
有没有人让 SLF4J / logback 与 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.
以前,通过将我的“logback.groovy”放在 [server]/conf 中,并将 logback 核心、经典 (0.9.28) 和 Groovy (1.8.0) JAR 放在 JBoss 5.1 中,我能够让我的应用程序在 JBoss 5.1 中运行[服务器]/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...
对于 JBoss 7.0.1,我已经设置好 Groovy 和 logback 模块(已创建 .index 文件),我的 EAR 的 MANIFEST.MF 声明了对这两个模块的依赖关系,并且我的“logback.groovy”部署在我的WAR 模块的 WEB-INF/classes,在我的 EAR 中。EAR 肯定部署正常 - 灯是绿色的......
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.
尽管如此,实际应用的唯一日志记录规则是在“standalone.xml”中设置的标准 console/server.log 规则。是的,我可以看到我的日志语句(所以 SLF4J 正在工作),但是我的 logback 规则、appender 等被忽略了。在任何日志记录中都没有对 logback 或 Groovy 的引用,所以我假设我没有做足够的工作来触发 logback 的加载和找到我的脚本。
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?
我还可以尝试其他一些事情,但最好知道其他人是否尝试过。如果他们没有,也许这表明我应该用 JBoss Logging 投入大量精力?
采纳答案by James R. Perkins
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.
JBoss AS7 使用 jboss-logmanager。我认为 logback appender 需要一个可以处理它们的日志管理器。我不确定如果您关闭日志管理器会发生什么。
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.
支持自定义 java.util.logging.Handler,因此您可以在处理程序中为 appender 编写包装器。我知道这可能并不理想,但它应该可以工作。
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.
我鼓励任何人使用 JBoss Logging,而不仅仅是因为我在做它:-) 它确实有一些不错的功能,比如 var-arg 日志方法,这首先吸引了我。还通过接口支持 i18n 日志记录和消息。
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.
此外,JBoss Logging 不仅仅是一个 API。这是一个完整的日志记录框架。在 JBoss Logging 的下一个版本中,我们将提供一种方法来指定您想要使用的日志管理器。这可能会使这样的事情变得更容易一些,但我必须承认我没有在 AS7 中进行过测试。如果我有时间,我会的。
回答by Ceki
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:
您确定 logback 处于活动状态吗?如果 logback 找不到配置文件,即 logback.groovy 或 logback.xml,它将在控制台上打印警告消息。输出应类似于:
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.)
你在控制台上看到任何这样的输出吗?如果没有,假设 Jboss 7 与 slf4j 绑定捆绑在一起,您可能已经在使用 Jboss 日志记录。(您对 slf4j api 的调用将发送到 jboss 日志记录而不是 logback。)
The Jboss folks should be contacted about using a logging backend other than jboss-logging.
关于使用 jboss-logging 以外的日志后端,应该联系 Jboss 人员。
Digging a little further, I noticed that JAS7 ships with a file called slf4j-jboss-logmanager-1.0.0.GA.jarlocated 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.
再深入一点,我注意到 JAS7 附带了一个名为slf4j-jboss-logmanager-1.0.0.GA.jar的文件,位于./modules/org/slf4j/impl/main/文件夹下。该文件的内容表明它绝对是一个 slf4j 绑定。我不知道 Jboss“模块”是如何工作的,但是如果您希望 slf4j 使用 logback-classic,则删除/禁用 slf4j-jboss-logmanager 是一种可行的方法。