Hibernate 4 Wildfly 8日志记录不起作用 [英] Hibernate 4 Wildfly 8 logging not working

查看:94
本文介绍了Hibernate 4 Wildfly 8日志记录不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何使Hibernate 4通过logback登录?我已将战争部署到wildfly 8 final,并且我正在将slf4j与logback一起使用.日志记录设置在应用程序中100%正常运行,并且控制台附加程序和文件附加程序均按预期工作.

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.

这是我做slf4j + logback的工作:

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

在WEB-INF中使用jboss-deployment-structure.xml排除了日志子系统:

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>

pom中包含了slf4j和logback依赖项:

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>

使用org.slf4j.Logger登录应用

Logging in app with org.slf4j.Logger

在logback.xml中添加了3个记录器:

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.

我唯一看到的来自休眠的东西是当我添加到我的persistence.xml中:

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>

但是,即使我的根记录程序设置为trace,它也会记录到服务器日志和控制台,而不记录到我的logback附加程序. .

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

logback ViewStatusMessagesServlet看起来很健康,并显示已注册的休眠记录器: 2014-02-23 19:02:37 INFO LoggerAction将记录器[org.hibernate.type]的设置级别设置为ALL

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将记录器[org.hibernate]的设置级别设置为TRACE

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

我还可以使用在persistence.xml中注册的hibernate.ejb.interceptor记录准备好的语句.不幸的是,这也没有提供任何获取查询参数的方法

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

有人可以帮我吗?

推荐答案

由于Hibernate不是您的部署的一部分,而是服务器的一部分,因此它无法在您的部署中使用回退配置. Hibernate将始终使用服务器日志记录配置.通常,这是在日志记录子系统中,但是如果将其删除,则由配置目录中的logging.properties文件控制.

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.

可能可以配置服务器(至少绝对不是域服务器)以使用logback.我没有尝试过,这需要一些工作.您必须确保启动时JBoss Modules不会加载jboss-logmanager模块,并且不会加载logback.同样,这可能会或可能不会起作用:)如果您这样做,尽管您将失去所有配置日志记录的管理功能,例如打开调试日志记录.

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.

这篇关于Hibernate 4 Wildfly 8日志记录不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆