简体   繁体   中英

Apache ActiveMQ/Artemis PeriodicRotatingFileHandler

I setup an Apache ActiveMQ Artemis broker where I want to create for each day a new artemis.log file.

I configured in logging.properties the PeriodicRotatingFileHandler , but it isn't working correctly.

It creates a log file for the day with the date in the filename (which is correct), but it does not create a log file for the other following days. It only creates new log files with the date when I restart the broker service.

Has anyone an example how the logging.properties should look like to achieve my plan?

The PeriodicRotatingFileHandler checks the time only on writing a new log record: PeriodicRotatingFileHandler.java#L115

The PeriodicRotatingFileHandler class could be extended, ie using a timer:

public class AutoPeriodicRotatingFileHandler extends PeriodicRotatingFileHandler {
   private Timer timer = new Timer();
   private long period = 5 * 60 * 1000;
   private ExtLogRecord timerLogRecord = new ExtLogRecord(Level.ALL, "TIMER", AutoPeriodicRotatingFileHandler.class.getName());

   public AutoPeriodicRotatingFileHandler() {
      initialize();
   }

   //TODO Add required constructors here

   public AutoPeriodicRotatingFileHandler(final File file, final String suffix, final boolean append, final int period) throws FileNotFoundException {
      super(file, suffix, append);
      this.period = period;
      initialize();
   }

   private void initialize() {
      timer.schedule(new TimerTask() {
         @Override
         public void run() {
            timerLogRecord.setMillis(System.currentTimeMillis());
            preWrite(timerLogRecord);
         }
      }, 0, period);
   }

   @Override
   public void close() throws SecurityException {
      timer.cancel();
      super.close();
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM