javaelasticsearchlogstashlogbacklogstash-logback-encoder

Logstash-Logback Encoder: “IllegalAccessError: failed to access class […]”


I try to send logs from a java application with the Logstash tcp socket appender to logstash. 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:

<configuration>
    <appender name="logstash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>[IP]:5010</destination>
        <encoder class="net.logstash.logback.encoder.LogstashEncoder">
            <fieldNames>
                <message>log_msg</message>
            </fieldNames>
        </encoder>
        <keepAliveDuration>5 minutes</keepAliveDuration>
    </appender>

<root>
<level value="info"/>
<appender-ref ref="logstash" />
</root>
</configuration>

But when I add the appender and start my java application, I get an error from the JVM Launcher "A Java Exception has occured" and I get the following console text:

Exception in thread "main" java.lang.IllegalAccessError: failed to access class ch.qos.logback.core.status.OnPrintStreamStatusListenerBase from class net.logstash.logback.status.LevelFilteringStatusListener (ch.qos.logback.core.status.OnPrintStreamStatusListenerBase and net.logstash.logback.status.LevelFilteringStatusListener are in unnamed module of loader 'app')
    at net.logstash.logback.status.LevelFilteringStatusListener.setDelegate(LevelFilteringStatusListener.java:67)
    at net.logstash.logback.appender.AsyncDisruptorAppender.start(AsyncDisruptorAppender.java:370)
    at net.logstash.logback.appender.AbstractLogstashTcpSocketAppender.start(AbstractLogstashTcpSocketAppender.java:1009)
    at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:90)
    at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
    at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)
    at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:179)
    at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:62)
    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:158)
    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:145)
    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:103)
    at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
    at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
    at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
    at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
    at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:412)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)

I included the logstash 6.3 jar-file and because of this error, I also tried it with an older version, 4.9. Does anybody know if that is compatible to logback 1.1.9? I'm not using Spring-Boot.

---------Edit 17.02.2020-----------

My input of the logstash.conf file (because I don't get any log from my java application):

input {
   tcp {
      mode => "server"
      port => 5010
      codec => json
   }
}

Solution

  • Solution:

    I updated logback from 1.1.9 to 1.2.3. As I replaced the jar files and addeded them to the class-path, I got over 600 times the following error-message: Logger cannot be resolved to a type. I fixed this by opening the properties in Eclipse from the logback project, going on "Order and Export" and setting a marker in every checkbox --> Apply and close. Now I don't get the IllegalAccessError any more and my java application is running fine. And I also now can see the logs in Logstash and Kibana :)

    I downloaded the following files:

    I downloaded them from here:

    https://mvnrepository.com/artifact/ch.qos.logback/logback-classic/1.2.3