MyBatis log4j2日志记录级别未更改

时间:2018-07-21 05:40:37

标签: log4j2 mybatis

对于MyBatis的log4j2日志记录,大多数其他帖子都提出了相反的要求。我正在记录MyBatis SQL,但我想减少它。

下面是我的log4j2.properties文件。 目前,我的rootLogger.level = ALL有效。 这很好地显示了所有日志消息,包括MyBatis Prepare SQL和参数列表。

当我将其更改为     rootLogger.level =致命 所有MyBatis消息都停止出现在控制台和日志文件中,其他消息也一样。 所以这很好用。

但是我想在正常情况下将MyBatis的日志记录级别设置为ERROR(或更高),其余部分保持为ALL。

当我更改     #MyBatis日志配置...     com.wert.bus.mappers =跟踪 达到其他任何级别,都不会生效。

我在“ com.wert”之前加了“ log4j”,“ log4j2”,“ log4j.logger”,“ log4j2.logger”前缀 但没有效果。

映射器的命名空间为com.wert.bus.mappers

第一次会话的输出:

[DEBUG] 2018-07-21 01:56:35.648 [main] LogFactory - Logging initialized using 'class org.apache.ibatis.logging.log4j2.Log4j2Impl' adapter.
[DEBUG] 2018-07-21 01:56:43.201 [main] PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[DEBUG] 2018-07-21 01:56:43.207 [main] PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[DEBUG] 2018-07-21 01:56:43.213 [main] PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[DEBUG] 2018-07-21 01:56:43.219 [main] PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[DEBUG] 2018-07-21 01:56:43.225 [main] PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[DEBUG] 2018-07-21 01:56:43.231 [main] PooledDataSource - PooledDataSource forcefully closed/removed all connections.
[DEBUG] 2018-07-21 01:56:43.237 [main] PooledDataSource - PooledDataSource forcefully closed/removed all connections.

查询的输出:

[DEBUG] 2018-07-21 02:00:10.047 [main] JdbcTransaction - Opening JDBC Connection
[DEBUG] 2018-07-21 02:00:19.739 [main] PooledDataSource - Created connection 105321150.
[DEBUG] 2018-07-21 02:00:19.823 [main] insertJobStatus - ==>  Preparing: insert bus_loc ( loc_date, loc_name, status, start_time, end_time) values ( ?, ?, ?, ?, ?) 
[DEBUG] 2018-07-21 02:00:24.512 [main] insertJobStatus - ==> Parameters: 2018-07-21 01:56:26.978(String), Boston(String), Prep(String), 2018-07-21 01:59:41(String), null
[DEBUG] 2018-07-21 02:00:25.034 [main] insertJobStatus - <==    Updates: 1

我错过了什么? 预先感谢您的帮助。

log4j2.properties

#status = trace  for log4j2 startup issues
#status other values: trace, debug, info, warn, error, fatal
status = error
dest = err

#Time interval to check for changes to file in seconds
monitorInterval = 300

name=BusLoggingConfig
property.filename=logs
appenders=console,rolling

# MyBatis logging configuration...
com.wert.bus.mappers=TRACE

appender.console.type=Console
appender.console.name=STDOUT
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %m%n
#appender.console.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

appender.rolling.type = RollingFile
appender.rolling.name = RollingFile
appender.rolling.fileName = ${filename}/Bus.log
appender.rolling.filePattern = logs/Bus-%d{yyyyMMdd-HHmmss}-%i.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %m%n
appender.rolling.policies.type = Policies
appender.rolling.policies.time.type = TimeBasedTriggeringPolicy
appender.rolling.policies.time.interval = 1
appender.rolling.policies.time.modulate = true
appender.rolling.policies.size.type = SizeBasedTriggeringPolicy
appender.rolling.policies.size.size=10MB
appender.rolling.strategy.type = DefaultRolloverStrategy
appender.rolling.strategy.max = 20

loggers=rolling
logger.rolling.name=com.wert.bus
#logger.rolling.level=debug
logger.rolling.additivity=true
logger.rolling.appenderRef.rolling.ref=RollingFile

rootLogger.level=ALL
rootLogger.appenderRefs=stdout
rootLogger.appenderRef.stdout.ref=STDOUT

1 个答案:

答案 0 :(得分:0)

问题之一是对子记录器使用可加性:

logger.rolling.additivity=true

此设置意味着每个日志记录事件将被处理两次。首次使用记录器com.wert.bus的附加器和级别,然后使用父记录器(在您的情况下为根)记录器。