How to use "ECS logging Java"?

I add log4j2-ecs-layout dependency to the application

log4j2.xml

COMMAND:
—————————————————————
java -javaagent:/root/elastic-apm-agent-1.11.0.jar
-Delastic.apm.service_name=my-cool-service -Delastic.apm.enable_log_correlation=true
-Delastic.apm.application_packages=org.example,org.another.example
-Delastic.apm.server_urls=http://localhost:8200 -jar target/dj-development-system-0.0.3-RELEASE.jar

I don't know how to reference "ecsjsonserializer"
How can I solve this error?

LOG:
—————————————————————
2019-11-04 02:24:03.536 [apm-server-healthcheck] INFO co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server is available: { "build_date": "2019-09-27T06:58:27Z", "build_sha": "971d864356e4438bf4a799a1fa052cfd0ce680b4", "version": "7.4.0"}
2019-11-04 02:24:03.635 [main] INFO co.elastic.apm.agent.configuration.StartupInfo - Starting Elastic APM 1.11.0 as my-cool-service on Java 11.0.5 (Oracle Corporation) Linux 3.10.0-862.el7.x86_64
2019-11-04 02:24:03.649 [apm-remote-config-poller] INFO co.elastic.apm.agent.configuration.ApmServerConfigurationSource - Received new configuration from APM Server: {transaction_sample_rate=1}
Exception in thread "main" java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.NoClassDefFoundError: co/elastic/logging/EcsJsonSerializer
at co.elastic.logging.log4j2.EcsLayout.(EcsLayout.java:97)
at co.elastic.logging.log4j2.EcsLayout.(EcsLayout.java:63)
at co.elastic.logging.log4j2.EcsLayout$Builder.build(EcsLayout.java:408)
at co.elastic.logging.log4j2.EcsLayout$Builder.build(EcsLayout.java:324)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:958)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:898)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:890)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:513)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:237)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:249)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:617)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:634)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:229)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:153)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:45)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:194)
at org.apache.commons.logging.LogFactory$Log4jLog.(LogFactory.java:199)
at org.apache.commons.logging.LogFactory$Log4jDelegate.createLog(LogFactory.java:166)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:109)
at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:99)
at org.springframework.boot.SpringApplication.(SpringApplication.java:189)
at com.djcps.djfileserver.DjdevelopmentsysApplication.main(DjdevelopmentsysApplication.java:34)
... 8 more
Caused by: java.lang.ClassNotFoundException: co.elastic.logging.EcsJsonSerializer
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 33 more

Make sure to include the transitive dependency ecs-logging-core when using manual dependency management.

I compiled ecs-logging-java-0.1.2.tar.gz and generated three files.
log4j-ecs-layout-0.1.2.jar
log4j-ecs-layout-0.1.2-javadoc.jar
log4j-ecs-layout-0.1.2-sources.jar

I've already referenced ‘log4j-ecs-layout-0.1.2.jar’ in the pom.xml file

I've already referenced ‘log4j-ecs-layout-0.1.2.jar’ in the pom.xml file.
But it doesn't work

Sorry, I found out I made a mistake. I forgot to use the 'ECS logging core' package

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.