0
votes

I have an inverse wish from most other posts regarding log4j2 logging of MyBatis. I am getting the MyBatis SQL logged, but I want to reduce it.

Below is my log4j2.properties file. At present, I have the rootLogger.level=ALL in effect. This is nicely displaying all log messages, including the MyBatis Prepare SQL and parameters list.

When I change it to rootLogger.level=FATAL all MyBatis messages stop appearing in console and log file, as do other messages. So this is working well.

But I would like to have MyBatis logging at level=ERROR (or higher) for normal circumstances and the rest staying at ALL.

When I change the # MyBatis logging configuration... com.wert.bus.mappers=TRACE to any other Level, it does not take effect.

I prefixed "log4j", "log4j2", "log4j.logger", "log4j2.logger" before "com.wert" but it had no effect.

The mappers have namespace com.wert.bus.mappers

The output on the first session:

[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.

The output on a query:

[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

What have I missed? Thanks in advance for your help.

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
Any help appreciated :-)user2242446

1 Answers

0
votes

One of the problems is using additivity for child logger:

logger.rolling.additivity=true

This settings means that every logging event will be processed twice. First time using appenders and levels for logger com.wert.bus and then by parent (in your case root) logger.