ActiveMQ Artemis 日志记录格式为 JSON
我使用的是 ActiveMQ Artemis 2.20.0,并且需要 JSON 格式的日志。
我尝试在 logging.properties
文件中使用 JSON 格式化程序,但收到错误
以下是我对logging.properties 所做的更改
# File handler configuration
handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.FILE.level=DEBUG
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=JSON
# Formatter pattern configuration
#formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
#formatter.PATTERN.properties=pattern
#formatter.PATTERN.pattern=%d %-5p [%c] %s%E%n
formatter.JSON=org.jboss.logmanager.formatters.JsonFormatter
formatter.JSON.properties=keyOverrides,metaData,prettyPrint,printDetails
formatter.JSON.constructorProperties=keyOverrides
formatter.JSON.keyOverrides=timestamp\=log_timestamp,level\=severity
formatter.JSON.metaData=@version\=1,service_id\=eric-eo-cm-cust-wf,json-format\=true
formatter.JSON.prettyPrint=false
formatter.JSON.printDetails=false
错误的堆栈跟踪如下:
No property "keyOverrides" type could be determined for formatter "JSON"Failed to read or configure the org.jboss.logmanager.LogManager
java.lang.IllegalArgumentException: Failed to instantiate class "org.jboss.logmanager.formatters.JsonFormatter" for formatter "JSON"
at org.jboss.logmanager.config.AbstractPropertyConfiguration$ConstructAction.validate(AbstractPropertyConfiguration.java:117)
at org.jboss.logmanager.config.LogContextConfigurationImpl.doPrepare(LogContextConfigurationImpl.java:336)
at org.jboss.logmanager.config.LogContextConfigurationImpl.prepare(LogContextConfigurationImpl.java:289)
at org.jboss.logmanager.config.LogContextConfigurationImpl.commit(LogContextConfigurationImpl.java:298)
at org.jboss.logmanager.PropertyConfigurator.configure(PropertyConfigurator.java:546)
at org.jboss.logmanager.PropertyConfigurator.configure(PropertyConfigurator.java:97)
at org.jboss.logmanager.LogManager.readConfiguration(LogManager.java:170)
at org.jboss.logmanager.LogManager.readConfiguration(LogManager.java:132)
at java.logging/java.util.logging.LogManager.readPrimordialConfiguration(LogManager.java:445)
at java.logging/java.util.logging.LogManager$2.run(LogManager.java:394)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.logging/java.util.logging.LogManager.ensureLogManagerInitialized(LogManager.java:382)
at java.logging/java.util.logging.LogManager.getLogManager(LogManager.java:430)
at java.logging/java.util.logging.Logger.demandLogger(Logger.java:648)
at java.logging/java.util.logging.Logger.getLogger(Logger.java:717)
at java.logging/java.util.logging.Logger.getLogger(Logger.java:701)
at org.apache.activemq.artemis.boot.Artemis.<clinit>(Artemis.java:40)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.jboss.logmanager.config.AbstractPropertyConfiguration$ConstructAction.validate(AbstractPropertyConfiguration.java:115)
... 16 more
Caused by: java.lang.NoClassDefFoundError: javax/json/Json
at org.jboss.logmanager.formatters.JsonFormatter.<init>(JsonFormatter.java:76)
... 21 more
ActiveMQ Artemis 日志记录是否后端有 JSON 依赖项以允许日志格式化为 JSON?
I'm using ActiveMQ Artemis 2.20.0, and I require logs in JSON format.
I tried to use a JSON formatter in the logging.properties
file but I get an error
The following is the change I made to logging.properties
# File handler configuration
handler.FILE=org.jboss.logmanager.handlers.PeriodicRotatingFileHandler
handler.FILE.level=DEBUG
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=JSON
# Formatter pattern configuration
#formatter.PATTERN=org.jboss.logmanager.formatters.PatternFormatter
#formatter.PATTERN.properties=pattern
#formatter.PATTERN.pattern=%d %-5p [%c] %s%E%n
formatter.JSON=org.jboss.logmanager.formatters.JsonFormatter
formatter.JSON.properties=keyOverrides,metaData,prettyPrint,printDetails
formatter.JSON.constructorProperties=keyOverrides
formatter.JSON.keyOverrides=timestamp\=log_timestamp,level\=severity
formatter.JSON.metaData=@version\=1,service_id\=eric-eo-cm-cust-wf,json-format\=true
formatter.JSON.prettyPrint=false
formatter.JSON.printDetails=false
The stack trace of error is as follows:
No property "keyOverrides" type could be determined for formatter "JSON"Failed to read or configure the org.jboss.logmanager.LogManager
java.lang.IllegalArgumentException: Failed to instantiate class "org.jboss.logmanager.formatters.JsonFormatter" for formatter "JSON"
at org.jboss.logmanager.config.AbstractPropertyConfiguration$ConstructAction.validate(AbstractPropertyConfiguration.java:117)
at org.jboss.logmanager.config.LogContextConfigurationImpl.doPrepare(LogContextConfigurationImpl.java:336)
at org.jboss.logmanager.config.LogContextConfigurationImpl.prepare(LogContextConfigurationImpl.java:289)
at org.jboss.logmanager.config.LogContextConfigurationImpl.commit(LogContextConfigurationImpl.java:298)
at org.jboss.logmanager.PropertyConfigurator.configure(PropertyConfigurator.java:546)
at org.jboss.logmanager.PropertyConfigurator.configure(PropertyConfigurator.java:97)
at org.jboss.logmanager.LogManager.readConfiguration(LogManager.java:170)
at org.jboss.logmanager.LogManager.readConfiguration(LogManager.java:132)
at java.logging/java.util.logging.LogManager.readPrimordialConfiguration(LogManager.java:445)
at java.logging/java.util.logging.LogManager$2.run(LogManager.java:394)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.logging/java.util.logging.LogManager.ensureLogManagerInitialized(LogManager.java:382)
at java.logging/java.util.logging.LogManager.getLogManager(LogManager.java:430)
at java.logging/java.util.logging.Logger.demandLogger(Logger.java:648)
at java.logging/java.util.logging.Logger.getLogger(Logger.java:717)
at java.logging/java.util.logging.Logger.getLogger(Logger.java:701)
at org.apache.activemq.artemis.boot.Artemis.<clinit>(Artemis.java:40)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.jboss.logmanager.config.AbstractPropertyConfiguration$ConstructAction.validate(AbstractPropertyConfiguration.java:115)
... 16 more
Caused by: java.lang.NoClassDefFoundError: javax/json/Json
at org.jboss.logmanager.formatters.JsonFormatter.<init>(JsonFormatter.java:76)
... 21 more
Does the ActiveMQ Artemis logging back-end have a JSON dependency to allow logs to format as JSON?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这很难看,但您需要:
下载 javax.json-1.1.jar。这与什么JBoss日志管理器兼容使用。
将
javax.json-1.1.jar
放入 Artemis 的 home 目录的lib
目录中(即解压 Artemis 的位置)存档)。修改实例中的
bin/artemis
脚本,将javax.json-1.1.jar
包含在-Xbootclasspath<中/代码>。已经有一行包含一些您可以修改的 jar(包括 JBoss 日志管理器),例如:
这很复杂,因为 Oracle 不允许 Eclipse 使用
javax
命名空间造成的混乱Oracle 向他们捐赠了 Java EE。对于具有 很多后果。由于 ActiveMQ Artemis 可以嵌入到 Java EE 和 Jarkata EE 环境中,因此无论提供什么 JSON API,我们都需要能够工作。因此,我们用自己的 API 包装了 javax.json,然后将该 API 和 Apache Johnzon 实现都融入到我们的发行版中。有关更多详细信息,请参阅 ARTEMIS-3546。包装和包装的问题阴影是 JBoss Logging 日志管理器等可能需要 javax.json 的外部库没有它,这就是您需要手动添加它的原因。希望 ActiveMQ Artemis 的未来版本能够更好地解决这个问题。
JSON 如下所示:
This is ugly, but you need to:
Download javax.json-1.1.jar. This is compatible with what JBoss Log Manager uses.
Put
javax.json-1.1.jar
in to thelib
directory of your Artemis' home directory (i.e. where you uncompressed the Artemis archive).Modify the
bin/artemis
script from the instance to includejavax.json-1.1.jar
in the-Xbootclasspath
. There is already a line which includes a few jars (including the JBoss Log Manager) which you can modify, e.g.:This is complicated because of the mess caused by Oracle not allowing Eclipse to use the
javax
namespace when Oracle donated Java EE to them. Everything namedjavax
had to be renamed tojakarta
for Jakarta EE 9 which has a lot of consequences. Since ActiveMQ Artemis can be embedded into both Java EE and Jarkata EE environments we need to be able to work no matter what JSON API is provided. Therefore, we wrapped thejavax.json
API with our own and then shaded both the API and the Apache Johnzon implementation into our distribution. See ARTEMIS-3546 for more details on that.The problem with wrapping & shading is that external libraries like JBoss Logging Log Manager which might need
javax.json
don't have it which is why you need to add it manually. Hopefully this will be sorted out better in a future version of ActiveMQ Artemis.Here's what the JSON looking looks like: