Log4j.properties in Spring boot

后端 未结 3 1975
青春惊慌失措
青春惊慌失措 2020-12-08 03:16

How to load Custom Log4j.properties file in Spring boot

My code in application.properties is here

logging.file=E:/Apps_Tek/apps-webservices-log/apps-         


        
3条回答
  •  心在旅途
    2020-12-08 03:46

    If you want spring boot to use log4j instead of its own default logging (logback) then you have to exclude default logging and include the log4j dependency for spring boot in your pom.xml:

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

    that way is going to look for your log4j.properties file located in src/main/resources.

    Also if you wish to use properties defined in you application.properties inside the log4j.properties file

    for example, you want to have log.file.path defined in your application.properties and use it on log4j.properties

    Then you have to define filtering inside your pom.xml:

    
        src/main/resources/application.properties
    
    
        
            src/main/resources
            
                log4j.properties
                     
            true
        
    
    

    That way you can have:

    log4j.appender.file.File=${log.file.path}/${project.artifactId}.log
    

    in your log4j.properties file

提交回复
热议问题