Hibernate 4 Wildfly 8 logging not working

蓝咒 提交于 2020-01-03 16:12:21

问题


How do I get hibernate 4 to log via logback? I have a war deployed to wildfly 8 final, and I am using slf4j with logback. The logging setup is working 100% in the application with both the console appender and file appender working as intended.

Here is what I did to get slf4j + logback working:

Excluded the logging subsystem with jboss-deployment-structure.xml in WEB-INF:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
    <deployment>
        <exclude-subsystems>
            <subsystem name="logging" />
        </exclude-subsystems>
    </deployment>
</jboss-deployment-structure>

Included slf4j and logback dependencies in pom:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.6</version>
</dependency>
<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.1.1</version>
</dependency>

Logging in app with org.slf4j.Logger

Added 3 loggers to logback.xml:

<logger name="my.package" level="TRACE"/>
<logger name="org.hibernate.type" level="ALL" />
<logger name="org.hibernate" level="TRACE" />

I don't see anything hibernate related in the logs.

The only time I see anything from hibernate is when I add to my persistence.xml:

<properties>
    <property name="hibernate.show_sql" value="true"/>
    <property name="hibernate.format_sql" value="true"/>
</properties>

But it logs to the server log and console and not to my logback appenders even if my root logger is set to trace . . .

The logback ViewStatusMessagesServlet looks healthy and shows the hibernate loggers registered: 2014-02-23 19:02:37 INFO LoggerAction Setting level of logger [org.hibernate.type] to ALL

2014-02-23 19:02:37 INFO LoggerAction Setting level of logger [org.hibernate] to TRACE

I can also get the prepared statement logged with hibernate.ejb.interceptor registered in persistence.xml. This also does not provide any method to get the query params unfortunately

Can anyone help me out?


回答1:


Because Hibernate is not part of your deployment and is part of the server it cannot use the logback configuration in your deployment. Hibernate will always use the servers logging configuration. Generally this is in the logging subsystem, but if removed is controlled by the logging.properties file in the configuration directory.

It might be possible to configure the server, standalone at least definitely not domain, to use logback. I have not tried this and it would take some work. You'd have to make sure that the jboss-logmanager module does not get loaded by JBoss Modules on boot and that logback does get loaded. Again this may or may not work :) If you do that though you will lose any management capabilities to configure logging at all, e.g. turning on debug logging.



来源:https://stackoverflow.com/questions/21971576/hibernate-4-wildfly-8-logging-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!