mybatis怎么配置log4j打印出sql语句
展开全部
提供一个项目的配置例子:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?xml version="1.0" encoding="UTF-8"?>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="Console" class="org.apache.log4j.ConsoleAppender">
<!-- 输出内容格式 -->
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c] - <%m>%n" />
</layout>
</appender>
<appender name="File" class="org.apache.log4j.DailyRollingFileAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler" />
<!-- 日志文件位置 -->
<param name="File" value="logs/wiCC.log" />
<!-- 是否在重新启动服务时,在原有的基础上追加日志 -->
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<!-- 输出内容格式 -->
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n" />
</layout>
</appender>
<logger name="org.springframework" additivity="false">
<level value="ERROR" />
<appender-ref ref="Console" />
</logger>
<logger name="org.apache.ibatis" additivity="false">
<level value="DEBUG" />
<appender-ref ref="Console" />
</logger>
<logger name="java.sql.Connection" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="Console" />
</logger>
<logger name="java.sql.Statement" additivity="false">
<level value="DEBUG" />
<appender-ref ref="Console" />
</logger>
<logger name="java.sql.PreparedStatement" additivity="false">
<level value="DEBUG" />
<appender-ref ref="Console" />
</logger>
<root>
<level value="info" />
<appender-ref ref="Console"/>
<appender-ref ref="File" />
</root>
</log4j:configuration>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?xml version="1.0" encoding="UTF-8"?>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="Console" class="org.apache.log4j.ConsoleAppender">
<!-- 输出内容格式 -->
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %p [%c] - <%m>%n" />
</layout>
</appender>
<appender name="File" class="org.apache.log4j.DailyRollingFileAppender">
<errorHandler class="org.apache.log4j.helpers.OnlyOnceErrorHandler" />
<!-- 日志文件位置 -->
<param name="File" value="logs/wiCC.log" />
<!-- 是否在重新启动服务时,在原有的基础上追加日志 -->
<param name="Append" value="true" />
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<!-- 输出内容格式 -->
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d %-5p [%c] %m%n" />
</layout>
</appender>
<logger name="org.springframework" additivity="false">
<level value="ERROR" />
<appender-ref ref="Console" />
</logger>
<logger name="org.apache.ibatis" additivity="false">
<level value="DEBUG" />
<appender-ref ref="Console" />
</logger>
<logger name="java.sql.Connection" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="Console" />
</logger>
<logger name="java.sql.Statement" additivity="false">
<level value="DEBUG" />
<appender-ref ref="Console" />
</logger>
<logger name="java.sql.PreparedStatement" additivity="false">
<level value="DEBUG" />
<appender-ref ref="Console" />
</logger>
<root>
<level value="info" />
<appender-ref ref="Console"/>
<appender-ref ref="File" />
</root>
</log4j:configuration>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询