Spring-Hibernate 日志记录 - 单独的日志文件
我正在使用 Spring 和在我的应用程序中使用 Hibernate,我想设置两个不同的日志文件 - 一个主日志文件用于所有非 sql 日志记录,另一个文件用于编写 sql 查询。这是我的 log4j.properties 文件。但是,虽然 sql 日志文件按预期工作。问题是主日志文件还包含 sql 查询。我应该在此处进行哪些更改才能停止将 sql 查询写入主日志文件..
#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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是 log4j 中附加程序的可加性行为。
只需将记录器
jdbc.sqltiming
的可加性设置为 false,其日志消息将不会传播到其父记录器的附加程序(即 app.log)参考:
有关 Appender 的更多信息,请参阅
Appenders 和布局
部分可加性This is the additivity behaviour of the appenders in log4j .
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)References:
See the section
Appenders and Layouts
for more information about Appender Additivity