码迷,mamicode.com
首页 > 其他好文 > 详细

log4j2.xml ------配置文件

时间:2019-08-14 16:38:38      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:ima   bcb   console   inter   ict   frame   style   enc   pid   

log4j2日志输出益处:西橡胶与 log4j 易于读取日志输出内容,且不需要保存到日志文件夹中,节约内存空间!!!

1.....pom.xml  需要导入的jar包:

 1    <!--日志-->
 2         <dependency>
 3             <groupId>log4j</groupId>
 4             <artifactId>log4j</artifactId>
 5             <version>1.2.17</version>
 6         </dependency>
 7         <dependency>
 8             <groupId>org.apache.logging.log4j</groupId>
 9             <artifactId>log4j-api</artifactId>
10             <version>2.10.0</version>
11         </dependency>
12         <dependency>
13             <groupId>org.apache.logging.log4j</groupId>
14             <artifactId>log4j-core</artifactId>
15             <version>2.10.0</version>
16         </dependency>
17         <dependency>
18             <groupId>org.apache.logging.log4j</groupId>
19             <artifactId>log4j-jcl</artifactId>
20             <version>2.9.1</version>
21         </dependency>
22         <dependency>
23             <groupId>org.apache.logging.log4j</groupId>
24             <artifactId>log4j-slf4j-impl</artifactId>
25             <version>2.9.1</version>
26         </dependency>
27         <dependency>
28             <groupId>org.apache.logging.log4j</groupId>
29             <artifactId>log4j-web</artifactId>
30             <version>2.9.1</version>
31         </dependency>
32         <dependency>
33             <groupId>org.apache.logging.log4j</groupId>
34             <artifactId>log4j-slf4j-impl</artifactId>
35             <version>2.9.1</version>
36         </dependency>
37         <dependency>
38             <groupId>org.slf4j</groupId>
39             <artifactId>slf4j-api</artifactId>
40             <version>1.7.25</version>
41         </dependency>

2.....   log4j2.xml -----文件配置信息

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <Configuration status="warn" monitorInterval="30" strict="true" schema="Log4J-V2.2.xsd">
 3     <Appenders>
 4         <Console name="Console" target="SYSTEM_OUT">
 5             <!-- 将日志输出到控制台 -->
 6             <PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %level [%C{36}.%M] - %msg%n"/>
 7         </Console>
 8         <!--将日志输出到文件中-->
 9         <file name="myLogFile" fileName="d:/log/ssm.log" append="true">
10             <PatternLayout pattern="%date{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %level [%C{36}.%M] - %msg%n"/>
11         </file>
12     </Appenders>
13 
14     <Loggers>
15         <!-- 全局配置 -->
16         <root level="info">
17             <!--普通日志要在哪里显示-->
18             <appenderRef ref="Console"/>
19             <appender-ref ref="myLogFile"/>
20         </root>
21 
22         <!-- 业务层日志 -->
23         <logger name="com.itheima.service" level="debug" additivity="false">
24             <appender-ref ref="Console"/>
25             <appender-ref ref="myLogFile"/>
26         </logger>
27 
28         <!-- 持久层日志 -->
29         <logger name="com.itheima.dao" level="debug" additivity="false">
30             <appender-ref ref="Console"/>
31             <appender-ref ref="myLogFile"/>
32         </logger>
33         <!-- 事务日志 -->
34         <logger name="org.springframework.jdbc" level="debug" additivity="false">
35             <appender-ref ref="Console"/>
36             <appender-ref ref="myLogFile"/>
37         </logger>
38     </Loggers>
39 
40 
41 </Configuration>

 

log4j2.xml ------配置文件

标签:ima   bcb   console   inter   ict   frame   style   enc   pid   

原文地址:https://www.cnblogs.com/wangshichang/p/11352743.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!