使用Log4j XML配置文件配置Hibernate日志记录? [英] Configuring Hibernate logging using Log4j XML config file?

查看:309
本文介绍了使用Log4j XML配置文件配置Hibernate日志记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到任何有关如何使用Log4j的XML样式配置文件配置Hibernate日志记录的文档。

I haven't been able to find any documentation on how to configure Hibernate's logging using the XML style configuration file for Log4j.

这是可能的,使用属性样式配置文件来控制Hibernate的日志记录?

Is this even possible or do I have use a properties style configuration file to control Hibernate's logging?

如果任何人有任何信息或链接到文档,它会感激。

If anyone has any information or links to documentation it would appreciated.

编辑:

为了澄清,我正在寻找一个实例的XML语法来控制Hibernate。


Just to clarify, I am looking for an example of the actual XML syntax to control Hibernate.

EDIT2:

这是我在XML配置文件中所拥有的。


Here is what I have in my XML config file.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <param name="Threshold" value="info"/>
        <param name="Target" value="System.out"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} [%t] %-5p %c{1} - %m%n"/>
        </layout>
    </appender>
    <appender name="rolling-file" class="org.apache.log4j.RollingFileAppender">
        <param name="file" value="Program-Name.log"/>
        <param name="MaxFileSize" value="1000KB"/>
    <!-- Keep one backup file -->
        <param name="MaxBackupIndex" value="4"/>
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d [%t] %-5p %l - %m%n"/>
        </layout>
    </appender>

    <root>
        <priority value ="debug" />
        <appender-ref ref="console" />
        <appender-ref ref="rolling-file" />
    </root>
</log4j:configuration>

日志记录工作正常,但我正在寻找一种方式来降低和控制hibernate日志记录独立于我的应用程序级别日志记录,因为它当前正在淹没我的日志。我已经找到使用偏好文件来做到这一点的例子,我只是想知道我如何能在一个XML文件中做到这一点。

Logging works fine but I am looking for a way to step down and control the hibernate logging in way that separate from my application level logging, as it currently is flooding my logs. I have found examples of using the preference file to do this, I was just wondering how I can do this in a XML file.

推荐答案

p>从 http:/ /docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html#configuration-logging

以下是列表的记录器类别:

Here's the list of logger categories:

Category                    Function

org.hibernate.SQL           Log all SQL DML statements as they are executed
org.hibernate.type          Log all JDBC parameters
org.hibernate.tool.hbm2ddl  Log all SQL DDL statements as they are executed
org.hibernate.pretty        Log the state of all entities (max 20 entities) associated with the session at flush time
org.hibernate.cache         Log all second-level cache activity
org.hibernate.transaction   Log transaction related activity
org.hibernate.jdbc          Log all JDBC resource acquisition
org.hibernate.hql.ast.AST   Log HQL and SQL ASTs during query parsing
org.hibernate.secure        Log all JAAS authorization requests
org.hibernate               Log everything (a lot of information, but very useful for troubleshooting) 

格式化为粘贴到log4j XML配置文件:

Formatted for pasting into a log4j XML configuration file:

<!-- Log all SQL DML statements as they are executed -->
<Logger name="org.hibernate.SQL" level="debug" />
<!-- Log all JDBC parameters -->
<Logger name="org.hibernate.type" level="debug" />
<!-- Log all SQL DDL statements as they are executed -->
<Logger name="org.hibernate.tool.hbm2ddl" level="debug" />
<!-- Log the state of all entities (max 20 entities) associated with the session at flush time -->
<Logger name="org.hibernate.pretty" level="debug" />
<!-- Log all second-level cache activity -->
<Logger name="org.hibernate.cache" level="debug" />
<!-- Log transaction related activity -->
<Logger name="org.hibernate.transaction" level="debug" />
<!-- Log all JDBC resource acquisition -->
<Logger name="org.hibernate.jdbc" level="debug" />
<!-- Log HQL and SQL ASTs during query parsing -->
<Logger name="org.hibernate.hql.ast.AST" level="debug" />
<!-- Log all JAAS authorization requests -->
<Logger name="org.hibernate.secure" level="debug" />
<!-- Log everything (a lot of information, but very useful for troubleshooting) -->
<Logger name="org.hibernate" level="debug" />

注意:大多数日志记录器使用DEBUG级别,然而org.hibernate.type使用TRACE。在Hibernate的早期版本中,org.hibernate.type也使用DEBUG,但是从Hibernate 3开始,必须将级别设置为TRACE(或ALL)才能看到JDBC参数绑定日志记录。

NB: Most of the loggers use the DEBUG level, however org.hibernate.type uses TRACE. In previous versions of Hibernate org.hibernate.type also used DEBUG, but as of Hibernate 3 you must set the level to TRACE (or ALL) in order to see the JDBC parameter binding logging.

并且类别指定为:

<logger name="org.hibernate">
    <level value="ALL" />
    <appender-ref ref="FILE"/>
</logger>

它必须放在根元素之前。

It must be placed before the root element.

这篇关于使用Log4j XML配置文件配置Hibernate日志记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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