Hibernate 4 Wildfly 8 logging not working

2019-06-22 08:57发布

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条回答
Viruses.
2楼-- · 2019-06-22 09:35

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.

查看更多
登录 后发表回答