Apache Artemis 日志记录以轮换日志文件
Apache Artemis logging to rotate log files
在已安装的 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(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.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
您的配置存在一些问题。
- 如果您想使用两者 基于时间和大小的旋转,您需要使用
org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler
。目前您使用的 org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
只会根据时间轮换。
- 您设置的旋转配置属性格式不正确。当您应该像其他属性一样使用 camel case 时,您却使用了
-
字符。我相信这是因为您正在阅读 JBoss EAP 的文档,它的配置格式与 ActiveMQ Artemis 使用的基于属性的普通配置略有不同。
- 您没有在
FILE
handler
的 properties
配置中指定旋转配置属性。
- 您使用的大小表示法
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
在已安装的 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(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.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
您的配置存在一些问题。
- 如果您想使用两者 基于时间和大小的旋转,您需要使用
org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler
。目前您使用的org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
只会根据时间轮换。 - 您设置的旋转配置属性格式不正确。当您应该像其他属性一样使用 camel case 时,您却使用了
-
字符。我相信这是因为您正在阅读 JBoss EAP 的文档,它的配置格式与 ActiveMQ Artemis 使用的基于属性的普通配置略有不同。 - 您没有在
FILE
handler
的properties
配置中指定旋转配置属性。 - 您使用的大小表示法
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