Rolling log Files & removing old log files

前端 未结 6 2001
长发绾君心
长发绾君心 2021-02-07 03:15

I am working on a Java SOAP based webservice application where I am writing stdout to a text file as log for our reference. That file is growing enormously, so I need to check f

6条回答
  •  醉话见心
    2021-02-07 03:59

    In log4j.xml you can try the following:

    
          
          
          
    
          
             
          
       
    

    The value tells log4j.xml to only keep 10 rotated log files around.

    Alternatively, if you are using a properties file (instead of the xml)

    log4j.appender.File=org.apache.log4j.RollingFileAppender
    log4j.appender.File.File=applog.log
    log4j.appender.File.Append=true
    log4j.appender.File.layout=org.apache.log4j.PatternLayout
    log4j.appender.File.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
    log4j.appender.[appenderName].MaxBackupIndex = 10
    

提交回复
热议问题