2017-10-05 285 views
0

我正在使用ELK Stack監視Im的Springboot Microservcies &。按照這個guide,我使用碼頭容器來運行ELK。LogStash - 無法實例化類型net.logstash.logback.appender.LogstashTcpSocketAppender

ELK運行起來,我開始我的Logstash,

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}"} }' 

我的雙響炮的詳細信息,

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> 

當我運行我的主類,我得到一個Logstash錯誤,

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 [email protected]: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 [email protected] - 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 [email protected]: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/, 

任何幫助非常感謝!我應該使用任何不同版本的Logstash依賴關係嗎?

回答

0

它似乎沒有正確添加依賴關係。嘗試添加

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

並運行mvn clean compile install。 它應該正常工作。