logstash-logback-encoder not works when deploys Tomcat
I’m having problems using the logstash-logback-encoder. I’m using the encoder:
<appender name="FILE-ERROR" class="ch.qos.logback.core.FileAppender"> <file>${LOG_FILE_PATH}${ERROR_FILE_NAME}</file> <append>true</append> <immediateFlush>true</immediateFlush> <!-- Filtro de level --> <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> <level>ERROR</level> </filter> **<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">** ...
My pom.xml is:
<dependency> <groupId>net.logstash.logback</groupId> <artifactId>logstash-logback-encoder</artifactId> <version>6.4</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.2.3</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> </dependency>
It works fine when I’m running through intellij, but when I deploy to Tomcat I have this error:
10-Jul-2020 18:47:34.906 INFO [localhost-startStop-2] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time. 10-Jul-2020 18:47:36.910 SEVERE [localhost-startStop-2] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/msid (16)]] at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:970) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1840) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.IllegalStateException: Logback configuration error detected: ERROR in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not create component [encoder] of type [net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder] java.lang.ClassNotFoundException: net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder ERROR in ch.qos.logback.core.joran.spi.Interpreter@22:113 - no applicable action for [jsonGeneratorDecorator], current ElementPath is [[configuration][appender][encoder][jsonGeneratorDecorator]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@23:24 - no applicable action for [providers], current ElementPath is [[configuration][appender][encoder][providers]] ERROR in ch.qos.logback.core.joran.spi.Interpreter@24:28 - no applicable action for [timestamp], current ElementPath is [[configuration][appender][encoder][providers][timestamp]] ...
Has anyone ever experienced this?
It looks like this is the root cause…
ERROR in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Could not create component [encoder] of type [net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder] java.lang.ClassNotFoundException: net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder
Double check that the logstash-logback-encoder jar is in the war that you are deploying to tomcat.
First, thanks for your answer Phil. Yes, some dependencies linked to the log were not present in the .war, even though they are included in pom.xml, they are not being generated in the "lib" folder. From what I could see, I was compiling the war using the Build artifacts from intellij and I wasn’t generating all the jars, but generating by the maven worked fine.
If anyone, knows anything about build artifacts, please share with us, but for now I can continue like this.
Thanks a lot for the help!