Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LogStash - Failed to instantiate type net.logstash.logback.appender.LogstashTcpSocketAppender

I am working on Springboot Microservcies & for monitoring Im using ELK Stack. I am using docker containers for running ELK as per this guide.

ELK is up and running, I am starting my Logstash by,

docker run -d -it --name logstash -p 5000:5000 logstash -e 
'input { tcp { port => 5000 codec => "json" } } 
output { elasticsearch { hosts => ["192.168.99.100"] index => "micro-%{serviceName}"} }'

My Pom details,

enter image description here

logback.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread, %X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="STASH"
        class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>192.168.99.100:5000</destination>

        <encoder
            class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <mdc /> <!-- MDC variables on the Thread will be written as JSON fields -->
                <context /> <!--Outputs entries from logback's context -->
                <version /> <!-- Logstash json format version, the @version field in the output -->
                <logLevel />
                <loggerName />

                <pattern>
                    <pattern>
                        {
                        "serviceName": "customer-service"
                        }
                    </pattern>
                </pattern>

                <threadName />
                <message />

                <logstashMarkers />
                <arguments />

                <stackTrace />
            </providers>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="STASH" />
    </root>
</configuration>

When I run my main class, I get an Logstash Error,

14:33:22,066 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
14:33:22,067 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
14:33:22,067 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [xyzxyz/logback.xml]
14:33:22,251 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
14:33:22,254 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
14:33:22,281 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [STDOUT]
14:33:22,297 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
14:33:22,450 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [net.logstash.logback.appender.LogstashTcpSocketAppender]
14:33:22,452 |-ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [net.logstash.logback.appender.LogstashTcpSocketAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type net.logstash.logback.appender.LogstashTcpSocketAppender
    at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type net.logstash.logback.appender.LogstashTcpSocketAppender
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:69)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:45)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:34)
    at  at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:52)
    at  at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:269)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:145)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:128)
    at  at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
    at  at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
    at  at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
    at  at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
    at  at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
    at  at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
    at  at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
    at  at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
    at  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
    at  at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
    at  at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
    at  at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
    at  at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:191)
    at  at pl.piomin.microservices.customer.Application.main(Application.java:14)
Caused by: java.lang.ClassNotFoundException: net.logstash.logback.appender.LogstashTcpSocketAppender
    at  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:56)
    at  ... 24 common frames omitted
14:33:22,452 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:67 - ActionException in Action for tag [appender] ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type net.logstash.logback.appender.LogstashTcpSocketAppender
    at ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type net.logstash.logback.appender.LogstashTcpSocketAppender
    at  at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:76)
    at  at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:269)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:145)
    at  at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:128)
    at  at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:165)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:152)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:110)
    at  at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
    at  at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
    at  at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
    at  at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
    at  at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
    at  at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
    at  at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
    at  at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
    at  at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
    at  at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
    at  at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
    at  at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
    at  at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:191)
    at  at pl.piomin.microservices.customer.Application.main(Application.java:14)
Caused by: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type net.logstash.logback.appender.LogstashTcpSocketAppender
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:69)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:45)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:34)
    at  at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:52)
    at  ... 21 common frames omitted
Caused by: java.lang.ClassNotFoundException: net.logstash.logback.appender.LogstashTcpSocketAppender
    at  at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:56)
    at  ... 24 common frames omitted
14:33:22,453 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to INFO
14:33:22,453 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [STDOUT] to Logger[ROOT]
14:33:22,456 |-ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an appender named [STASH]. Did you define it below instead of above in the configuration file?
14:33:22,456 |-ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - See http://logback.qos.ch/codes.html#appender_order for more details.
14:33:22,456 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
14:33:22,458 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@2096442d - Registering current configuration as safe fallback point

14:33:24.286 [main, ,] ERROR o.s.boot.SpringApplication - Application startup failed
java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type [net.logstash.logback.appender.LogstashTcpSocketAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type net.logstash.logback.appender.LogstashTcpSocketAppender
ERROR in ch.qos.logback.core.joran.spi.Interpreter@11:67 - ActionException in Action for tag [appender] ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type net.logstash.logback.appender.LogstashTcpSocketAppender
ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an appender named [STASH]. Did you define it below instead of above in the configuration file?
ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - See http://logback.qos.ch/codes.html#appender_order for more details.
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:151)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:195)
    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:65)
    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:50)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:106)
    at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:277)
    at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:255)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:224)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:200)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
    at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:65)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:330)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:140)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:84)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:1)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:166)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:121)
    at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:111)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:65)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:330)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180)
    at pl.piomin.microservices.customer.Application.main(Application.java:14)
14:33:24.295 [main, ,] INFO  o.s.b.l.ClasspathLoggingApplicationListener - Application failed to start with classpath: [xyzxyz/, 

Any help is greatly appreciated!! Should I be using any different version Logstash dependencies?

like image 586
John Seen Avatar asked Oct 05 '17 09:10

John Seen


People also ask

Why does Logstash-Logback-encoder throw an exception when adding a status listener?

The exception occurs because logstash-logback-encoder versions >= 6.0 reference logback's ch.qos.logback.core.status.OnPrintStreamStatusListenerBase class when adding a default status listener. OnPrintStreamStatusListenerBase was made public in logback 1.1.10, and was package-private before then.

What version of Logback does the Java app support?

The java app. already works with logback 1.1.9 (slf4j) and other appenders. Now I added the following lines to the logback-test.xml:

Does Logstash-Logback-encoder work with IntelliJ IDEA?

It should work properly. Show activity on this post. Sometimes it is an issue with ID E. If you copied your project from other machine, in Intellij Idea try to File -> Invalidate Caches & Restart -> Maven -> Reload All Maven Projects. Show activity on this post. I had the same issue with logstash-logback-encoder version 6.6

When was onprintstreamstatuslistenerbase made public?

OnPrintStreamStatusListenerBase was made public in logback 1.1.10, and was package-private before then. Applying any of the above solutions will avoid the exception you encountered. However, keep in mind that logstash-logback-encoder versions >= 4.8 are compiled and tested against logback 1.2.x.


Video Answer


2 Answers

It Seems you haven't added dependencies properly. Try to add

<dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>4.9</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.2.3</version>
        </dependency>

and run mvn clean compile install. It should work properly.

like image 118
Prince Avatar answered Oct 21 '22 06:10

Prince


Sometimes it is an issue with IDE. If you copied your project from other machine, in Intellij Idea try to

File -> Invalidate Caches & Restart -> Maven -> Reload All Maven Projects.
like image 24
Zon Avatar answered Oct 21 '22 06:10

Zon