如何关闭mybatis日志
发布网友
发布时间:2022-04-25 22:56
我来回答
共1个回答
热心网友
时间:2022-06-18 11:01
使用环境:Mybatis_3.2.8 + Log4j2_2.1
首先要说明的是:
Mybatis是用Mapper类的全路径名,作为logger的名称的。
Mybatis中,打印SQL语句的日志级别是DEBUG,而打印SQL执行结果集的日志级别是TRACE。
比如,我们的应用是: com.test.app
而mapper类所在的路径为: com.test.app.
则我们可以分别控制应用的业务日志和SQL日志的输出。
如下的Log4j2.xml将输出所有业务日志,以及SQL语句日志
引用
1
2
3
4
5
6
7
8
9
10
<Loggers>
<Logger name="com.test.app." additivity="false" level="<a href="https://www.baidu.com/s?wd=DEBUG&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YYnHwbuju9ujw-nHK-nWPB0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EP1fdPWnvPjnzn1mYP1RLnjDz" target="_blank" class="-highlight">DEBUG</a>">
<AppenderRef ref="sql_log"/>
<AppenderRef ref="Console"/>
</Logger>
<Logger name="com.test.app" additivity="false" level="<a href="https://www.baidu.com/s?wd=TRACE&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YYnHwbuju9ujw-nHK-nWPB0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EP1fdPWnvPjnzn1mYP1RLnjDz" target="_blank" class="-highlight">TRACE</a>">
<AppenderRef ref="biz_<a href="https://www.baidu.com/s?wd=debug&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YYnHwbuju9ujw-nHK-nWPB0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EP1fdPWnvPjnzn1mYP1RLnjDz" target="_blank" class="-highlight">debug</a>"/>
<AppenderRef ref="Console"/>
</Logger>
</Loggers>
如下的Log4j2.xml将输出所有业务日志,以及SQL语句日志,SQL语句执行结果日志
引用
1
2
3
4
5
6
7
8
9
10
<Loggers>
<Logger name="com.test.app." additivity="false" level="<a href="https://www.baidu.com/s?wd=TRACE&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YYnHwbuju9ujw-nHK-nWPB0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EP1fdPWnvPjnzn1mYP1RLnjDz" target="_blank" class="-highlight">TRACE</a>">
<AppenderRef ref="sql_log"/>
<AppenderRef ref="Console"/>
</Logger>
<Logger name="com.test.app" additivity="false" level="TRACE">
<AppenderRef ref="biz_debug"/>
<AppenderRef ref="Console"/>
</Logger>
</Loggers>