在 Catalina.out 中控制 SQL 日志记录级别 [英] Control SQL logging level in Catalina.out

查看:70
本文介绍了在 Catalina.out 中控制 SQL 日志记录级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的应用程序可在Tomcat 8和Linux上运行.我们附带了log4j.xml,该战争控制着应用程序日志记录的日志记录级别.log4j还定义了SQL的日志记录级别.

Our app runs on Tomcat 8 and Linux. We have log4j.xml shipped with the war that controls the level of logging for our applications logging. The log4j also defines logging levels for SQL.

在hibernate.cfg.xml中,"hibernate.show_sql"设置为true.

In hibernate.cfg.xml, the "hibernate.show_sql" is set to true.

<property name="hibernate.show_sql">true</property>

在$ CATALINA_BASE/conf/logging.properties中

In $CATALINA_BASE/conf/logging.properties

对 ConsoleAppender 的所有引用:

All references to ConsoleAppender:

log4j.appender.stdout=org.apache.log4j.ConsoleAppender

已被删除,因此除SQL语句外没有任何内容发送到std.

Are removed, so nothing is sent to std out except for the SQL statements.

"hibernate.show_sql> true,将所有正在处理的SQL语句发送到catalina.out –请注意,catalina.out是仅在Linux/Unix计算机上创建的文件.

The: "hibernate.show_sql">true, sends all SQL statements being processed to catalina.out – please note that catalina.out is a file created only on Linux/Unix machines.

我读到"hibernate.show_sql>为真,在DEBUG级别记录了SQL语句.问题是我想以ERROR级别记录这些语句,但不知道如何控制级别?

I read that "hibernate.show_sql">true, logs the SQL statements at DEBUG level. The problem is that I want to log those statements at ERROR level but don’t know how to control the level?

我了解到SQL日志记录的级别可以由log4j.xml控制,但是在log4j.xml中对其进行更改不会影响catalina.out的记录方式.有谁知道如何控制catalina.out中的SQL登录仅处于ERROR级别?

I read that that level for SQL logging can be controlled by log4j.xml, but changing it in log4j.xml has no effect on how the catalina.out is being logged. Does anyone know how can I control the SQL logging in catalina.out to be only at ERROR level?

下面是log4j.xml.

Below is log4j.xml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
<log4j:configuration>
<appender name="mylog" class="org.apache.log4j.RollingFileAppender">        
    <param name="File" value="${catalina.base}/logs/mylog.log" />
    <param name="Threshold" value="TRACE" />
    <param name="Append" value="true" />
    <param name="MaxFileSize" value="300MB" />
    <param name="MaxBackupIndex" value="10" />
    <layout class="it.openutils.log4j.FilteredPatternLayout">
        <param name="ConversionPattern"
            value="%d{ISO8601} %5p [%t] Executor:%X{Executor} Type:%X{Type}     A:%X{Account} C:%X{Campaign} %c{1}:%L - %m%n" />            
    </layout>
</appender>

<logger name="org.hibernate.SQL" additivity="false">
    <level value="ERROR" />
    <appender-ref ref="mylog" />
</logger>

<logger name="org.hibernate">
        <level value="ERROR"/>
</logger>
<logger name="org.hibernate.jdbc.JDBCContext">
        <level value="ERROR"/>
</logger>

<root>
    <level value="info" />
    <appender-ref ref="mylog" />
</root>

推荐答案

由于我仍然无法找到将Catalina.out的级别设置为ERROR的方法,因此我决定全部关闭SQL日志记录.因此,我将log4j.xml中的所有级别都更改回INFO,并在hibernate.cfg.xml中将此属性设置为false.

Since I was not able to find anyway to set the level to ERROR for Catalina.out, I decided to turn off the SQL logging all together. So I changed all levels in log4j.xml back to INFO and set this property to false in hibernate.cfg.xml.

<property name="hibernate.show_sql">false</property>

一段时间记录后,我注意到在Catalina.out中没有任何记录,除非发生错误,因此在这种情况下,错误和异常将记录在Catalina.out中,而不是常规SQL语句中,(几乎)我最初试图实现的目标.我不知道您为什么会这样,以及在哪里/如何定义这些日志记录级别.但是希望能对某人有所帮助.

After a while logging, I noticed that there is nothing being logged in Catalina.out unless an error happens, so in this case, the errors and exceptions are being logged into Catalina.out and not the regular SQL statements, which is (almost) something I was trying to achieve at the first place. I do not know why that’s the case thou and where/how those logging levels are defined. But hope that helps somebody.

这篇关于在 Catalina.out 中控制 SQL 日志记录级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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