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 MVC整合 Log4jSpringMVC
- Spring配置log4jSpring
- 在Spring中配置log4jSpring
- Mybatis、maven專案中整合log4j (17)MyBatisMaven
- spring cloud多模組專案框架搭建-整合SLF4J和log4j日誌元件SpringCloud框架元件
- spring進步 — log4j的學習Spring
- Spring Boot整合Spring BatchSpring BootBAT
- Spring Boot整合Spring SecuritySpring Boot
- Spring Boot整合Spring AopSpring Boot
- Spring 整合 MyBatisSpringMyBatis
- mybatis整合springMyBatisSpring
- ActiveMq整合SpringMQSpring
- Spring整合MyBatisSpringMyBatis
- Spring整合JUnitSpring
- Spring整合WebSocketSpringWeb
- Spring Cloud 整合SpringCloud
- MyBatis(九) 整合Spring、整合SpringMVCMyBatisSpringMVC
- Spring Boot:整合Spring Data JPASpring Boot
- spring:spring與mybatis的整合SpringMyBatis
- spring-boot+spring-session整合SpringbootSession
- spring+redis的整合,使用spring-data-redis來整合SpringRedis
- Unit08: Spring與MyBatis整合 、 Spring整合MyBatis應用SpringMyBatis
- Spring Boot整合rabbitmqSpring BootMQ
- Spring框架|整合JdbcTemplateSpring框架JDBC
- Spring Boot 整合 rabbitmqSpring BootMQ
- Spring Boot 整合 elasticsearchSpring BootElasticsearch
- Spring Boot 整合 dockerSpring BootDocker
- Spring Boot 整合 elkSpring Boot
- Spring Boot 整合 ApolloSpring Boot
- Spring Boot整合RedisSpring BootRedis
- Spring Boot 整合redisSpring BootRedis
- Spring Boot 整合 MyBatisSpring BootMyBatis
- Spring與ActiveMQ整合SpringMQ
- Spring整合Mybatis plusSpringMyBatis
- Spring Boot整合SocketSpring Boot
- spring與redis整合SpringRedis
- Spring 整合 HibernateSpring
- Mybatis與Spring整合MyBatisSpring