Is it possible to configure log4j to create a new file with every run of the application?

前端 未结 4 555
逝去的感伤
逝去的感伤 2020-12-10 11:22

For example, the first time I run an application (or immediately after I clear out the /logs directory), I want log4j to write the application\'s logs to a file called log.0

4条回答
  •  误落风尘
    2020-12-10 12:18

    Solution with log4j2:

            
            
            
                %level\t%d{yyyy-MM-dd HH:mm:ss} %c: %m%n
            
            
                
                
                
            
        
    

    Note OnStartupTriggeringPolicy and %i in filePattern. This way, Log4j will create new log file with index each time you run App.

提交回复
热议问题