Logback: how to change log directory from “tomcat/bin” to application related?

后端 未结 2 670
长发绾君心
长发绾君心 2021-02-15 10:53

I want to use slf4j with logback for logging.

You can see my logback.xml below:


    

        
2条回答
  •  失恋的感觉
    2021-02-15 11:40

    Well, I solved my problem but it is not very good solution (by my opinion).

    First of all I put absolute path to log file in .property file. For example:

    logback.log.location=d:\Tomcat\tomcat_8.0.0-RC5\webapps\module\logs
    

    Then I use that property in my logback.xml:

    
        
        
            ${logback.log.location}\module.log
            
                
                    %date %level [%thread] %logger{10} [%file:%line] %msg%n
                
            
        
    
        
            
        
    
    

    More details you can see here. This is an example, that I use.

    But in solution above we have environment specific absolute path to the logs. This is ugly. Of course, we can use system variable CATALINA_HOME to avoid absolute path. But, as I know, CATALINA_HOME can be undefined. Or, we can use another instance of tomcat, that is not in CATALINA_HOME.

    Maybe someone have more nice solution that will be environment independent?


    UPDATE

    Another solution:

    Just use relative (to tomcat\bin) path instead absolute in logback.xml:

    
        
            ..\webapps\module\module.log
            
                
                    %date %level [%thread] %logger{10} [%file:%line] %msg%n
                
            
        
    
        
            
        
    
    

    It was the first idea, that I try to implement. I don't know, why it didn't work before. Maybe there were other problems. Moreover this and this articles confused me.

    But now this solution work fine. This is exactly that I am looking for =)

提交回复
热议问题