Spring Boot使用log4j2日志框架

默认你已经搭建好spring boot框架

  1. 去除对spring-boot-starter-logging的依赖,在spring boot的jar包中,目测logging的jar包是spring-boot-starter的依赖包,所有其他对spring-boot-starter有依赖的包,包括spring-boot-starter都要去除logging,包括spring-boot-starter-test、spring-boot-starter-web、spring-boot-starter-thymeleaf、spring-boot-starter,将如下代码加入对应的dependency中
       
          
             org.springframework.boot
             spring-boot-starter-logging
          
       
    
  2. 加入log4j2的jar包

        org.springframework.boot
        spring-boot-starter-log4j2
       
  3. application.yml的配置,就是指定log4j2配置文件的位置,其他所有关于日志的就在里面配就可以了
    logging:
      config: classpath:log4j2.xml
    # application.properties里面可以写logging.config=classpath:log4j2.xml
  4. log4j2.xml配置
    
    
        
            
                
                
                
                
            
    
            
            
            
                
                    
                    
                
                
                
                    
                    
                
                
                
                
                    
                        
                        
                    
                
            
    
            
            
                
                    
                    
                    
                
                
                
                    
                    
                
                
                    
                        
                        
                    
                
            
    
            
            
                
                    
                    
                
                
                
                    
                    
                
                
                    
                        
                        
                    
                
            
    
            
            
                
                
                
                    
                    
                
                
                    
                        
                        
                    
                
            
        
    
        
            
                
                
                
                
                
                
            
            
            
            
            
    
        
    
  5. mybatis日志指定

如上指定打印指定Mapper接口的SQL日志,name可以指定到具体接口,也可以指定到包,这就可以根据需求那些SQL可以打印,那些不需要打印

你可能感兴趣的:(Spring,Boot配置)