Apache Artemis 日志记录以轮换日志文件
Posted
技术标签:
【中文标题】Apache Artemis 日志记录以轮换日志文件【英文标题】:Apache Artemis logging to rotate log files 【发布时间】:2021-11-01 08:18:29 【问题描述】:在已安装的 Artemis 代理 logging.properties
中,我已包含以下配置以设置日志轮换
# File handler configuration
handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.FILE.level=DEBUG
handler.FILE.properties=suffix,append,autoFlush,fileName
# for log rotate
handler.FILE.suffix=.yyyy-MM-dd-HH-mm
handler.FILE.append=true
handler.FILE.autoFlush=true
handler.FILE.fileName=$artemis.instance/log/artemis.log
handler.FILE.formatter=PATTERN
## Added for Log rotate
handler.FILE.rotate-size=25k
handler.FILE.max-backup-index=3
handler.FILE.rotate-on-boot=true
当我重新启动 Artemis 代理服务时,通过上述更改,请注意日志正在轮换到 artemis.log.2021-09-02-14
但是对于rotate-size
25k,文件没有得到旋转。
以下是属性的 jboss 文档。
properties | data type | description |
---|---|---|
max-backup-index | Integer | The maximum number of size-rotated logs that are kept. When this number is reached, the oldest log is reused. Default: 1. This setting only applies to logs that are rotated based on file size. Note that if a file is rotated with a date format suffix, it will not be purged using the max-backup-index option. |
rotate-size | String | The maximum size that the log file can reach before it is rotated. |
在这种情况下,我的期望是:
每小时轮换一次日志,只管理 3 组文件artemis.log
artemis.log.2020-09-02-16
artemis.log.2020-09-02-15
artemis.log.2020-09-02-14
purged files
artemis.log.2020-09-02-13
有没有办法检查 Artemis 代理触发日志轮换的频率?
是不是配置不正确。
使用 Artemis 2.17 版本 更新属性后,我在重新启动服务时遇到异常。
2021-09-03 02:02:59,468 WARN [org.apache.activemq.artemis.core.server] AMQ222276: Failed to process changes to the logging configuration file: file:/<borker-path>/etc/logging.properties: java.lang.IllegalArgumentException: No property "rotateSize" setter found for handler "FILE"
at org.jboss.logmanager.config.AbstractPropertyConfiguration.setPropertyValueExpression(AbstractPropertyConfiguration.java:194) [jboss-logmanager-2.1.10.Final.jar:2.1.10.Final]
at org.jboss.logmanager.config.AbstractPropertyConfiguration.setPropertyValueString(AbstractPropertyConfiguration.java:155) [jboss-logmanager-2.1.10.Final.jar:2.1.10.Final]
at org.apache.activemq.artemis.core.server.LoggingConfigurationUpdater.configureProperties(LoggingConfigurationUpdater.java:351) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.LoggingConfigurationUpdater.configureHandler(LoggingConfigurationUpdater.java:323) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.LoggingConfigurationUpdater.configureHandlerNames(LoggingConfigurationUpdater.java:363) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.LoggingConfigurationUpdater.configureLogger(LoggingConfigurationUpdater.java:193) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.LoggingConfigurationUpdater.configure(LoggingConfigurationUpdater.java:111) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.LoggingConfigurationUpdater.configure(LoggingConfigurationUpdater.java:85) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.LoggingConfigurationFileReloader.reload(LoggingConfigurationFileReloader.java:46) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.reload.ReloadManagerImpl$ReloadRegistry.check(ReloadManagerImpl.java:124) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.reload.ReloadManagerImpl.tick(ReloadManagerImpl.java:67) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.reload.ReloadManagerImpl.run(ReloadManagerImpl.java:48) [artemis-server-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.ActiveMQScheduledComponent.runForExecutor(ActiveMQScheduledComponent.java:313) [artemis-commons-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.core.server.ActiveMQScheduledComponent.lambda$bookedRunForScheduler$2(ActiveMQScheduledComponent.java:320) [artemis-commons-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:42) [artemis-commons-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.utils.actors.OrderedExecutor.doTask(OrderedExecutor.java:31) [artemis-commons-2.17.0.jar:2.17.0]
at org.apache.activemq.artemis.utils.actors.ProcessorBase.executePendingTasks(ProcessorBase.java:65) [artemis-commons-2.17.0.jar:2.17.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [rt.jar:1.8.0_191]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [rt.jar:1.8.0_191]
at org.apache.activemq.artemis.utils.ActiveMQThreadFactory$1.run(ActiveMQThreadFactory.java:118) [artemis-commons-2.17.0.jar:2.17.0]
可能我需要检查源代码。
这是我使用的默认logging.properties
# Root logger option
loggers=org.eclipse.jetty,org.jboss.logging,org.apache.activemq.artemis.core.server,org.apache.activemq.artemis.utils,org.apache.activemq.artemis.utils.critical,org.apache.activemq.artemis.journal,org.apache.activemq.artemis.jms.server,org.apache.activemq.artemis.integration.bootstrap,org.apache.activemq.audit.base,org.apache.activemq.audit.message,org.apache.activemq.audit.resource
# Root logger level
logger.level=INFO
# ActiveMQ Artemis logger levels
logger.org.apache.activemq.artemis.core.server.level=INFO
logger.org.apache.activemq.artemis.journal.level=INFO
logger.org.apache.activemq.artemis.utils.level=INFO
# if you have issues with CriticalAnalyzer, setting this as TRACE would give you extra troubleshooting information.
# but do not use it regularly as it would incur in some extra CPU usage for this diagnostic.
logger.org.apache.activemq.artemis.utils.critical.level=INFO
logger.org.apache.activemq.artemis.jms.level=INFO
logger.org.apache.activemq.artemis.integration.bootstrap.level=INFO
logger.org.eclipse.jetty.level=WARN
# Root logger handlers
logger.handlers=FILE,CONSOLE
# to enable audit change the level to INFO
logger.org.apache.activemq.audit.base.level=ERROR
logger.org.apache.activemq.audit.base.handlers=AUDIT_FILE
logger.org.apache.activemq.audit.base.useParentHandlers=false
logger.org.apache.activemq.audit.resource.level=ERROR
logger.org.apache.activemq.audit.resource.handlers=AUDIT_FILE
logger.org.apache.activemq.audit.resource.useParentHandlers=false
logger.org.apache.activemq.audit.message.level=ERROR
logger.org.apache.activemq.audit.message.handlers=AUDIT_FILE
logger.org.apache.activemq.audit.message.useParentHandlers=false
# Console handler configuration
handler.CONSOLE=org.jboss.logmanager.handlers.ConsoleHandler
handler.CONSOLE.properties=autoFlush
handler.CONSOLE.level=DEBUG
handler.CONSOLE.autoFlush=true
handler.CONSOLE.formatter=PATTERN
# File handler configuration
handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.FILE.level=DEBUG
handler.FILE.properties=suffix,append,autoFlush,fileName,rotateSize,maxBackupIndex,rotateOnBoot
handler.FILE.suffix=.yyyy-MM-dd-HH-mm
handler.FILE.append=true
handler.FILE.autoFlush=true
handler.FILE.fileName=$artemis.instance/log/artemis.log
handler.FILE.formatter=PATTERN
## Added for Log rotate
handler.FILE.rotateSize=25600
handler.FILE.maxBackupIndex=3
handler.FILE.rotateOnBoot=true
# Formatter pattern configuration
formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.PATTERN.properties=pattern
formatter.PATTERN.pattern=%d %-5p [%c] %s%E%n
#Audit logger
handler.AUDIT_FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.AUDIT_FILE.level=INFO
handler.AUDIT_FILE.properties=suffix,append,autoFlush,fileName,
handler.AUDIT_FILE.suffix=.yyyy-MM-dd
handler.AUDIT_FILE.append=true
handler.AUDIT_FILE.autoFlush=true
handler.AUDIT_FILE.fileName=$artemis.instance/log/audit.log
handler.AUDIT_FILE.formatter=AUDIT_PATTERN
formatter.AUDIT_PATTERN=org.jboss.logmanager.formatters.PatternFormatter
formatter.AUDIT_PATTERN.properties=pattern
formatter.AUDIT_PATTERN.pattern=%d [AUDIT](%t) %s%E%n
【问题讨论】:
【参考方案1】:您的配置存在一些问题。
如果您想同时使用基于时间和大小的旋转,您需要使用org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler
。目前您使用的是org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
,它只会根据时间轮换。
您的轮换配置属性格式不正确。当您应该像其他属性一样使用 camel case 时,您正在使用 -
字符。我相信这是因为您正在阅读 JBoss EAP 的文档,它的配置格式与 ActiveMQ Artemis 使用的基于属性的普通配置略有不同。
您没有在 properties
配置中为 FILE
handler
指定轮换配置属性。
您使用的大小表示法 k
在 ActiveMQ Artemis 使用的基于属性的普通配置中不受支持。
尝试改用这个:
handler.FILE=org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler
handler.FILE.level=DEBUG
handler.FILE.properties=suffix,append,autoFlush,fileName,rotateSize,maxBackupIndex,rotateOnBoot
handler.FILE.suffix=.yyyy-MM-dd-HH-mm
handler.FILE.append=true
handler.FILE.autoFlush=true
handler.FILE.fileName=$artemis.instance/log/artemis.log
handler.FILE.formatter=PATTERN
handler.FILE.rotateSize=25600
handler.FILE.maxBackupIndex=3
handler.FILE.rotateOnBoot=true
【讨论】:
我包含了推荐值,看起来 setter 无法识别。编辑带有异常消息的问题。 我在logging.properties
中使用了这个精确的配置,一切正常。可以粘贴完整的logging.properties
吗?
使用的 logging.properties 是在创建代理期间生成的默认属性。当我重新启动时,我注意到日志文件被创建为新文件。
你没有使用我推荐的配置。您仍在使用handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
。此处理程序没有 rotateSize
参数,这就是您收到错误的原因。您需要使用handler.FILE=org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler
。我更新了我的答案以使这个配置错误更清楚。
我的错,你是对的。它没有抛出异常..以上是关于Apache Artemis 日志记录以轮换日志文件的主要内容,如果未能解决你的问题,请参考以下文章