slf4j打印⽇志必须的三个依赖包正⽂
⽇志相关包 slf4j打印⽇志必须的三个依赖包
slf4j假设使⽤log4j做为底层⽇志⼯具,运⾏以上程序需要三个包:
jar、
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.21</version>
</dependency>
log4j.properties⽂件配置:
### set log levels ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.versionPattern=%d{yyyy-MM-dd HH:mm:ss.SSSXXX} %-5p [%t] [%C %L] %m%n
Append=true
File=${scheduleProject}logs/root.log
layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSSXXX} %-5p [%t] [%C %L] %m%n
layout=org.apache.log4j.PatternLayout
MaxBackupIndex=50
MaxFileSize=20MB
=org.apache.log4j.RollingFileAppender
ipPermission=400
logPermission=600
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="/xml/ns/javaee" xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/xml/ns/javaee /xml/ns/javaee/web-app_3_1.xsd"
version="3.1" metadata-complete="true">
<display-name>Archetype Created Web Application</display-name>
<!-- 加载log4j的配置⽂件log4j.properties -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:config/log4j.properties</param-value>
</context-param>
<!-- 设定刷新⽇志配置⽂件的时间间隔,这⾥设置为10s -->
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>10000</param-value>
</context-param>
<!--加载Spring框架中的log4jLog4jConfigListener-->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- 为避免项⽬间冲突,定义唯⼀的 webAppRootKey -->
<context-param>
<param-name>webAppRootKey</param-name>
<param-value>scheduleProject</param-value>
</context-param>
<!-- 注册字符集过滤器 -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<!-- 指定字符集编码 -->
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 注册前端控制器 -->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/spring-*.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<!--默认匹配所有的请求-->
<url-pattern>/</url-pattern>
log4j2不打印日志</servlet-mapping>
</web-app>
本免费提供csdn下载服务,海量IT学习资源,如果你准备⼊IT坑,励志成为优秀的程序猿,那么这些资源很适合你,包括但不限于java、go、python、springcloud、elk、嵌⼊式、⼤数据、⾯试资料、前端等资源。同时我们组建了⼀个技术交流,⾥⾯有很多⼤佬,会不定时分享技术⽂章,如果你想来⼀起学习提⾼,可以后台回复【2】,免费邀请加技术交流互相学习提⾼,会不定期分享编程IT 相关资源。
扫码关注,精彩内容第⼀时间推给你

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。