开发者

With log4j, is it possible to hide JDBC returned column values with org.hibernate.type TRACE logging enabled?

开发者 https://www.devze.com 2023-01-30 19:00 出处:网络
I\'m tracking Hibernate\'s generated SQL statements and their bound parameters using log4j on a Seam Framework project. Currently I have the below configuration:

I'm tracking Hibernate's generated SQL statements and their bound parameters using log4j on a Seam Framework project. Currently I have the below configuration:

jboss-log4j.xml:

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">

...

   <appender name="SQL" class="org.jboss.logging.appender.DailyRollingFileAppender">
      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
      <param name="File" value="${jboss.server.log.dir}/sql.log"/>
      <param name="Append" value="true"/>
      <layout class="org.apache.log4j.PatternLayout">
         <param name="ConversionPattern" value="%d{ABSOLUTE} [%c{1}] %X{username} %m%n"/>
      </layout>
   </appender>

   <category name="org.hibernate">
       <priority value="INFO"/>
       <appender-ref ref="SQL"/>
   </category>

   <category name="org.hibernate.SQL" additivity="false">
       <priority value="DEBUG"/>
       <appender-ref ref="SQL"/>
   </category>

   <category name="org.hibernate.HQL" additivity="false">
       <priority value="DEBUG"/>
       <appender-ref ref="SQL"/>
   </category>

   <category name="org.hibernate.type" additivity="false">
       <priority value="TRACE"/>
       <appender-ref ref="SQL"/>
   </category>

</log4j:configuration>

The problem is the generated sql.log file becomes too unwieldy as at least 100k of text is appended to the log on each page visit. I would like to filter out the JDBC messages for "returning as column " and instead only track INSERT/UPDATE queries but can't find such an option in Hibernate or log4j's documentation. Removing these lines using a manual scripting process isn't desirable since I wan开发者_JS百科t to reduce disk reads/writes on the web server.

Is it possible to stop these returned JDBC values of SELECT queries from being added to the log file while keeping the parameter value bindings?


Unfortunately both logging statements:

binding '...' to parameter: ...

and

returning '...' as column: ...

originate from the same class org.hibernate.type.NullableType and are logged on the same TRACE level. This means that you can't simply filter the latter log statement leaving the first one untouched.

However, if you are using Logback, filters might come to the rescue.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号