Set Logging Level in Spring Boot via Environment Variable

后端 未结 10 1016
刺人心
刺人心 2020-12-23 08:57

Should it be possible to set logging levels through environment variables alone in a Spring Boot application?

I don\'t want to use application.properties

10条回答
  •  囚心锁ツ
    2020-12-23 09:42

    Here's an example using Logback with Janino to conditionally include different logging configs via properties or environmental variables... The base config, logback.xml is using conditionals for development console logging or production file logging... just drop the following files in /resources/


    logback.xml


    
    
        
            
                
                
            
        
        
            
                
                
            
        
    
    

    dev.xml

    
        
            
                utf-8
                %-30([%p] [%c:%L]) » %m%n%rEx
            
        
    
        
        
    
        
            true
        
    
        
            
        
    
    
    

    pro.xml

    
        
        
        
    
        
            
                FILE_NAME_PATTERN
                7
            
            
                ${FILE_LOG_PATTERN}
            
        
    
        
            512
            
        
    
        
        
    
        
            
        
    
    
    

提交回复
热议问题