简体   繁体   English

的logback <logger> 日志来自jboss-logging时忽略级别

[英]logback <logger> level ignored when logs come from jboss-logging

My web application (deployed on tomcat 7) is using hibernate 4.2 which logs using jboss-logging. 我的Web应用程序(部署在tomcat 7上)正在使用hibernate 4.2,它使用jboss-logging进行日志记录。 Jboss logging is finding slf4j on the path and uses it. Jboss日志记录在路径上找到slf4j并使用它。 In turn, I have logback-classic to output the logs. 反过来,我有logback-classic来输出日志。 Everything works nicely, but I cannot customize the root logging level, ie 一切都很好,但我无法自定义根日志记录级别,即

<logger name="o.h.cfg.annotations" level="info"/>
<logger name="rest.helpers" level="info"/>

<root level="debug">
    <appender-ref ref="STDOUT" />
</root>

Results in: 结果是:

logback-test 16:47:03.689 [http-bio-8080-exec-5] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider logback-test 16:47:03.689 [http-bio-8080-exec-5] DEBUG org.jboss.logging - 日志提供者:org.jboss.logging.Slf4jLoggerProvider

logback-test 16:47:04.244 [http-bio-8080-exec-5] DEBUG ohcfg.annotations.EntityBinder logback-test 16:47:04.244 [http-bio-8080-exec-5] DEBUG ohcfg.annotations.EntityBinder

logback-test 10:00:11.911 [localhost-startStop-1] INFO rest.helpers.MyApplication logback-test 10:00:11.911 [localhost-startStop-1] INFO rest.helpers.MyApplication

For messages coming from jboss (ohcfg.annotations.*), level is set to info, but a debug message is printed. 对于来自jboss(ohcfg.annotations。*)的消息,level设置为info,但会打印调试消息。 When I use slf4j directly (rest.helpers.*), it correctly filters out my debug messages, and prints my info messages. 当我直接使用slf4j(rest.helpers。*)时,它会正确过滤掉我的调试消息,并打印我的信息消息。

Now, if root log level is set to "none", allowing some debug messages will print all of them: 现在,如果root日志级别设置为“none”,则允许一些调试消息将打印所有这些消息:

<logger name="o.h.cfg.annotations" level="debug"/>
<logger name="rest.helpers" level="debug"/>
<root level="none"/>

logback-test 10:22:25.926 [localhost-startStop-1] DEBUG rest.helpers.MyApplication -dMyApplication() Aug 2, 2013 10:22:26 AM org.glassfish.jersey.server.ApplicationHandler initialize INFO: Initiating Jersey application logback-test 10:22:25.926 [localhost-startStop-1] DEBUG rest.helpers.MyApplication -dMyApplication()2013年8月2日上午10:22:26 org.glassfish.jersey.server.ApplicationHandler初始化INFO:启动Jersey应用程序

logback-test 10:22:26.253 [localhost-startStop-1] INFO rest.helpers.MyApplication logback-test 10:22:26.253 [localhost-startStop-1] INFO rest.helpers.MyApplication

logback-test 10:22:42.995 [http-bio-8080-exec-5] DEBUG org.jboss.logging - Logging Provider: org.jboss.logging.Slf4jLoggerProvider logback-test 10:22:42.995 [http-bio-8080-exec-5] DEBUG org.jboss.logging - 日志提供者:org.jboss.logging.Slf4jLoggerProvider

logback-test 10:22:43.025 [http-bio-8080-exec-5] DEBUG org.hibernate.type.BasicTypeRegistry logback-test 10:22:43.025 [http-bio-8080-exec-5] DEBUG org.hibernate.type.BasicTypeRegistry

I have not allowed org.hibernate debug messages, why did they appear? 我没有允许org.hibernate调试消息,它们为什么会出现? i verified that the right config file is taken (by changing the log format) 我验证了正确的配置文件(通过更改日志格式)

Please help me make sense of this. 请帮助我理解这一点。

My classpath contains 我的类路径包含

  • slf4j-api 1.6.1 slf4j-api 1.6.1
  • jul-to-slf4j 1.6.1 jul-to-slf4j 1.6.1
  • log4j-over-slf4j 1.6.1 log4j-over-slf4j 1.6.1
  • logback-core 1.0.33 logback-core 1.0.33
  • logback-classic 1.0.33 logback-classic 1.0.33
  • jboss-logging 3.1.0.GA. jboss-logging 3.1.0.GA.

Both logback.xml and logback-test.xml are in the classpath. logback.xml和logback-test.xml都在类路径中。 logback.xml contains <root level="warn"> and no further specialization logback.xml包含<root level="warn"> ,没有进一步的专业化

I had the same problem with freemarker however in my case freemarker was not using the log4j-over-slf4j bridge but used log4j directly (i had it in my classpath without knowing (through a maven dependency)). 我遇到了与freemarker相同的问题,但是在我的情况下,freemarker没有使用log4j-over-slf4j桥,而是直接使用了log4j(我在我的类路径中有它而不知道(通过maven依赖))。

I discovered the problem when i told logback to log to a file and the freemarker logs still arrived on stdout. 当我告诉logback记录到文件并且freemarker日志仍然到达stdout时,我发现了这个问题。

The solution was to explicitly exclude the log4j dependency from a maven lib i used. 解决方案是明确地从我使用的maven lib中排除log4j依赖项。

To turn off unwanted logs just simply set root level to OFF and register logger for package/class you want to print in your logging destination. 要关闭不需要的日志,只需将根级别设置为OFF,并为要在日志记录目标中打印的包/类注册记录器。

<logger name="rest" level="INFO"/>
<root level="OFF">
    <appender-ref ref="STDOUT" />
</root>

I had a similar problem with hibernate using HikariCP and logback within tomcat 8. I use JNDI to define the Hikari pool globally on tomcat. 我在使用HikariCP和tomcat 8中的logback时遇到了类似的hibernate问题。我使用JNDI在tomcat上全局定义Hikari池。

So I ended with adding Hikari, logback and slf4j jars only under CATALINA_HOME/lib . 所以我最后只在CATALINA_HOME/lib下添加了Hikari,logback和slf4j jar。

In such a case, it took me quite a while to discover that in such case, the logback.xml configuration file must also be under CATALINA_HOME/lib to be found by tomcat and not under CATALINA_HOME/conf where the rest of tomcat config is done. 在这种情况下,我花了很logback.xml才发现在这种情况下, logback.xml配置文件也必须在CATALINA_HOME/lib ,由tomcat找到,而不是CATALINA_HOME/conf下,其余的tomcat配置完成。

Hope it can help someone. 希望它可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Hibernate从jboss-logging切换到logback? - How to switch Hibernate from jboss-logging to logback? 如何禁用Jboss日志记录 - How to disable Jboss-logging 使用jboss-logging的应用程序应何时使用log4j - Application using jboss-logging when it should use log4j Hibernate 5依赖项在jboss-logging上本身具有版本冲突 - Hibernate 5 dependency has version conflict with itself on jboss-logging Java 代码从 logback.xml 覆盖 hibernate 日志记录级别 - Java code to override hibernate logging level from logback.xml 配置 org.hibernate.SQL 记录器时,Logback 显示 DEBUG 输出,root 级别为 INFO - Logback shows DEBUG output with root at level INFO when org.hibernate.SQL logger configured 通过JMX在运行时在Logback中更改Hibernate SQL日志记录级别 - Changing Hibernate SQL logging level in Logback at runtime through JMX java.lang.NoSuchMethodError:JBoss中的org.jboss.logging.Logger.getMessageLogger - java.lang.NoSuchMethodError: org.jboss.logging.Logger.getMessageLogger in JBoss 避免在jboss控制台上打印休眠日志 - avoid hibernate logs from printing on jboss console Hibernate 5.2.1 Glassfish 4.1.1项目错误:java.lang.NoSuchMethodError:org.jboss.logging.Logger.debugf - Hibernate 5.2.1 Glassfish 4.1.1 Project Error : java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM