【问题标题】:Apache ActiveMQ/Artemis PeriodicRotatingFileHandlerApache ActiveMQ/Artemis PeriodicRotatingFileHandler
【发布时间】:2020-10-09 12:14:09
【问题描述】:

我设置了一个 Apache ActiveMQ Artemis 代理,我想在其中每天创建一个新的 artemis.log 文件。

我在logging.properties 中配置了PeriodicRotatingFileHandler,但它不能正常工作。

它会在文件名中包含日期的当天创建一个日志文件(这是正确的),但它不会为接下来的几天创建一个日志文件。它只会创建新的日志文件,其中包含我重新启动代理服务的日期。

有没有人举例说明 logging.properties 应该如何实现我的计划?

【问题讨论】:

  • 你能和PeriodicRotatingFileHandler分享你的logging.properties吗?
  • handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler handler.FILE.level=INFO handler.FILE.properties=suffix,append,autoFlush,fileName handler.FILE.suffix=.yyyy- MM-dd handler.FILE.append=true handler.FILE.autoFlush=true handler.FILE.fileName=${artemis.instance}/log/artemis.log handler.FILE.formatter=PATTERN
  • 我的意思是你的整个logging.properties 文件只是为了确保一切都配置得当。另外,请使用详细信息更新您的问题,而不是在评论中添加它们。
  • 另外,请说明您使用的是哪个版本的 ActiveMQ Artemis。
  • 应该每天轮换一次,但只有一次记录新的日志消息。

标签: logging jboss activemq-artemis


【解决方案1】:

PeriodicRotatingFileHandler 仅在写入新日志记录时检查时间:PeriodicRotatingFileHandler.java#L115

PeriodicRotatingFileHandler 类可以扩展,即使用计时器:

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();
   }
}

【讨论】:

  • 感谢您的信息。你能告诉我文件的路径吗? (在 SLES 环境中工作)
  • 如果您使用命令./bin/artemis create broker --user admin --password admin 创建代理,则日志文件处理程序的默认路径将为${artemis.instance}/log/artemis.log
  • 对不起,如果我的问题不是那么具体。我的意思是 PeriodicRotatingFileHandler.jave 文件的路径,我可以用计时器扩展它
  • 你可以在github.com/jboss-logging/jboss-logmanager/blob/2.1.10.Final/src/…找到PeriodicRotatingFileHandler.java
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-21
  • 2019-09-30
  • 2020-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-10
相关资源
最近更新 更多