Spring整合log4j
web.xml
配置一個Log4jConfigListener的監聽器,引數為log4j配置檔案的配置
<!-- 整合log4j -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<description>log4j listener</description>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
log4j.properties檔案配置
log4j.rootLogger=INFO,console,dailyFile
#控制檯輸出日誌記錄器定義
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Threshold=INFO
log4j.appender.console.ImmediateFlush=true
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n
#日誌檔案記錄器定義
#這個類能夠設定日誌檔案的生成頻率
log4j.appender.dailyFile=org.apache.log4j.DailyRollingFileAppender
#日誌檔案的位置
log4j.appender.dailyFile.File= ${catalina.home}/logs/mfo
#每個檔案的最大大小
log4j.appender.dailyFile.MaxFileSize = 10240KB;
#備份檔案的數量,超過上面的大小後,生成備份
log4j.appender.dailyFile.MaxBackupIndex = 2;
#允許追加
log4j.appender.dailyFile.Append=true
#日誌資訊的格式定義
log4j.appender.dailyFile.layout=org.apache.log4j.PatternLayout
log4j.appender.dailyFile.layout.ConversionPattern=%-d{yyyy-MM-dd HH\:mm\:ss} [%c]-[%p] [%t] (%F\:%L) ->%m %n
#記錄的資訊級別是info以上的
log4j.appender.dailyFile.Threshold=INFO
#表示每天生成檔案
log4j.appender.dailyFile.DatePattern='_'yyyy-MM-dd'.log'
呼叫
private static Logger logger = Logger.getLogger(需要記錄日誌的類名.class);
//呼叫
logger.debug("--------debug------");
logger.info("---------test---------");
logger.error("-----------error-----");
相關文章
- Spring配置log4jSpring
- Mybatis、maven專案中整合log4j (17)MyBatisMaven
- spring cloud多模組專案框架搭建-整合SLF4J和log4j日誌元件SpringCloud框架元件
- Spring Boot整合Spring SecuritySpring Boot
- Spring Boot整合Spring BatchSpring BootBAT
- Spring Boot整合Spring AopSpring Boot
- MyBatis(九) 整合Spring、整合SpringMVCMyBatisSpringMVC
- mybatis整合springMyBatisSpring
- Spring 整合 HibernateSpring
- ActiveMq整合SpringMQSpring
- Spring Cloud 整合SpringCloud
- Spring 整合 MyBatisSpringMyBatis
- Spring整合WebSocketSpringWeb
- Spring整合JUnitSpring
- Spring整合MyBatisSpringMyBatis
- spring:spring與mybatis的整合SpringMyBatis
- Spring Boot:整合Spring Data JPASpring Boot
- spring+redis的整合,使用spring-data-redis來整合SpringRedis
- spring-boot 整合 spring-securitySpringboot
- spring-boot 整合 spring-sessionSpringbootSession
- Spring Boot整合Spring Cloud Netflix元件Spring BootCloud元件
- 整合RabbitMQ&SpringMQSpring
- Spring與ActiveMQ整合SpringMQ
- spring boot整合jooqSpring Boot
- spring與redis整合SpringRedis
- Spring Boot整合SocketSpring Boot
- Spring整合Mybatis plusSpringMyBatis
- Mybatis與Spring整合MyBatisSpring
- Spring整合JUnit,MybatisSpringMyBatis
- spring cloud 整合 nacosSpringCloud
- SpringBoot整合Spring SecuritySpring Boot
- Spring 持久層整合Spring
- Spring Boot整合rabbitmqSpring BootMQ
- Spring框架|整合JdbcTemplateSpring框架JDBC
- Spring Boot整合RedisSpring BootRedis
- Spring Boot 整合redisSpring BootRedis
- Spring Boot 整合 rabbitmqSpring BootMQ
- Spring Boot 整合 elasticsearchSpring BootElasticsearch