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?
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: