问题描述
我正在使用Spring&在我的应用程序中休眠后,我想设置两个不同的日志文件-一个主日志文件所有非sql日志记录,另一个用于编写sql查询的文件.这是我的log4j.properties文件.但是当sql日志文件按预期方式工作时.问题是主日志文件还包含sql查询.我应该在此处进行哪些更改以停止将sql查询写入主日志文件.
I am using Spring & Hibernate in my application and I want to set up two different log files - one main log file all the non-sql logging and another file for writing sql queries. This is my log4j.properties file.. But while the sql log file is working as expected..the issue is that the main log file also contains sql queries.. What changes should I make here to to stop writing sql queries to main log file..
#application log properties
log4j.appender.rollingFile = org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollingFile.File = C:\\myapp\\logs\\app.log
log4j.appender.rollingFile.Threshold = TRACE
log4j.appender.rollingFile.DatePattern = '.'yyyy-MM-dd
log4j.appender.rollingFile.layout = org.apache.log4j.PatternLayout
log4j.appender.rollingFile.layout.ConversionPattern=%d %5p [%C:%M:%L] - %m%n
log4j.rootLogger = ERROR, rollingFile
#hibernate properties
log4j.appender.file = org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File = C:\\myapp\\logs\\sql.log
log4j.appender.file.Threshold = TRACE
log4j.appender.file.DatePattern = '.'yyyy-MM-dd
log4j.appender.file.layout = org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d %5p [%C:%M:%L] - %m%n
log4j.logger.jdbc.sqltiming = DEBUG, file
推荐答案
这是log4j中附加程序的可加行为.
This is the additivity behaviour of the appenders in log4j .
只需将记录器 jdbc.sqltiming
的可加性设置为false,其日志消息就不会传播到其父记录器的附加程序(即app.log)
Just set the additivity for the logger jdbc.sqltiming
to false and its log messages will not be propagated to its parent loggers' appenders (i.e. app.log)
log4j.additivity.jdbc.sqltiming = false
参考:
有关Appender的更多信息,请参见 Appenders和Layouts
部分可加性
See the section Appenders and Layouts
for more information about Appender Additivity
这篇关于Spring-Hibernate日志记录-单独的日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!