springboot 整合log4j2 记录

    很少写博客;看了很多网上的教程,自己也试过了很多,有些问题也记录下来了希望能帮到其他朋友。

SpringBoot整合log4j2很简单,两步:

1、导入依赖。

2、配置log4j2-spring.xml。

 

1、我配置成功的依赖:

  
            org.springframework.boot
            spring-boot-starter
			
				
					org.springframework.boot
					spring-boot-starter-logging
				
			
        
		
		
			org.springframework.boot
			spring-boot-starter-log4j2
		

    网上很多都有说是 排除 spring-boot-starter-web 下的logging,然而我没有成功,不论怎么做都是报下面的错误;最后是需要在spring-boot-starter 下面排除,可能只是我的是这样子。。。

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/D:/programData/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/D:/programData/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.10.0/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

   2、log4j2-spring.xml 配置文件;参考着网上写的然后改的;打印输出的日志很详细,有sql语句,数据库信息等等。

该文件放置位置是 :\src\main\resources\log4j2-spring.xml,名字相对固定,这些操作后就可以了,然后运行时就可以自动读取这个文件了。





    
        
        HurdPlatform
        
        ${sys:crtServerPort:-8080}
        
        UTF-8
        
        300MB
        
        Logs
        
        
            
            
            
            |%d{yyyy-MM-dd HH:mm:ss.SSS}|%t|${PORT}|${APPNAME}|%logger|%M|%p|%m%n
        
    

    
        
        
            
            
            
            
            
        
        
        
        
        
        
            
            
                
                
            
            
                
                
                
                
            
        

        
        
        
            
            
                
                
                
                
            
            
                
                
                
                
            
        

        
        
            
            
                
            
            
                
                
            
        

        
        
            
            
                
            
            
                
                
            
        

        
        
            
            
                
            
            
                
            
        
    

    
        
        
        
        

        
        
        
        
        
        

        
            
            
            
            
        
    


 

你可能感兴趣的:(java)