You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2019/12/06 09:19:10 UTC

[GitHub] [skywalking] gonedays commented on issue #4016: How to integrate with logstash-logback-encoder in json format

gonedays commented on issue #4016: How to integrate with logstash-logback-encoder in json format
URL: https://github.com/apache/skywalking/issues/4016#issuecomment-562496351
 
 
   > Please answer these questions before submitting your issue.
   > 
   > * Why do you submit this issue?
   > * [x]  Question or discussion
   > * [ ]  Bug
   > * [ ]  Requirement
   > * [ ]  Feature or performance improvement
   > 
   > ### Question
   > * What do you want to know?
   >   We use logstash-logback-encoder in custom json format, but failed to print TID in log file.
   > 
   > ### Bug
   > * Which version of SkyWalking, OS and JRE?
   >   SkyWalking: 6.5.0
   >   OS: linux or windows
   >   JRE: JDK8
   >   logback-core: 1.1.11
   > * Which company or project?
   >   test
   > * What happen?
   >   If possible, provide a way for reproducing the error. e.g. demo application, component version.
   > 
   > 1. Add dependency in maven pom.xml
   > 
   > ```
   > <dependency>
   >           <groupId>net.logstash.logback</groupId>
   >           <artifactId>logstash-logback-encoder</artifactId>
   >           <version>5.1</version>
   >       </dependency>
   >   <dependency>
   >           <groupId>org.apache.skywalking</groupId>
   >           <artifactId>apm-toolkit-logback-1.x</artifactId>
   >           <version>6.5.0</version>
   >       </dependency>
   > ```
   > 
   > 1. config logback xml
   > 
   > ```
   > <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
   >             <providers>
   >                 <mdc/>
   >                 <timestamp>
   >                     <timeZone>UTC</timeZone>
   >                 </timestamp>
   >                 <provider class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.logstash.TraceIdJsonProvider"/>
   >                 <pattern>
   >                     <pattern>
   >                         {
   >                         "level": "%level",
   >                         "ip": "${IP}",
   >                         "service": "${APP_NAME:-}",
   >                         "trace": "%X{X-B3-TraceId:-}",
   >                         "TID": "%X{TID}",
   >                         "tid": "%X{tid}",
   >                         "span": "%X{X-B3-SpanId:-}",
   >                         "exportable": "%X{X-Span-Export:-}",
   >                         "pid": "${PID:-}",
   >                         "thread": "%thread",
   >                         "class": "%logger{1.}:%L",
   >                         "message": "%message",
   >                         "stackTrace": "%exception{10}"
   >                         }
   >                     </pattern>
   >                 </pattern>
   >             </providers>
   >         </encoder>
   > ```
   > 
   > 1. No TID in log file.
   >    log example:
   > 
   > ```
   > {"@timestamp":"2019-12-06T07:52:10.162+00:00","level":"INFO","ip":"169.254.234.242","service":"dlsgateway","trace":"","TID":"","tid":"","span":"","exportable":"","pid":"17352","thread":"http-nio-8989-exec-1","class":"com.netflix.loadbalancer.DynamicServerListLoadBalancer:222","message":"Using serverListUpdater PollingServerListUpdater","stackTrace":""}
   > ```
   > 
   > With above configuration, faield to print TID, but with below configuration, it works:
   > 
   > ```
   >  <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
   >             <layout class="org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout">
   >                 <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level logger_name:%logger{36} - [%tid] - message:%msg%n</pattern>
   >             </layout>
   >         </encoder>
   > ```
   > 
   > Please help how to handle it. Appreciate your help.
   > 
   > ### Requirement or improvement
   > * Please describe about your requirements or improvement suggestions.
   
   Get solution for this, just add the Converter in logback.xml:
   ```
   <configuration>
   <conversionRule conversionWord="tid" converterClass="org.apache.skywalking.apm.toolkit.log.logback.v1.x.LogbackPatternConverter"/>
   
   <!--appender-->
   <appender name="logstash" class="ch.qos.logback.core.rolling.RollingFileAppender">
           <file>${LOG_PATH:-.}/${APP_NAME}/${APP_NAME}_json.log</file>
           <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
               <fileNamePattern>${LOG_PATH:-.}/${APP_NAME}/${APP_NAME}_json.log.%d{yyyy-MM-dd}.gz</fileNamePattern>
               <maxHistory>30</maxHistory>
           </rollingPolicy>
           <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
               <providers>
                   <timestamp>
                       <timeZone>UTC</timeZone>
                   </timestamp>
                   <pattern>
                       <pattern>
                           {
                           "level": "%level",
                           "ip": "${IP}",
                           "service": "${APP_NAME:-}",
                           "tid": "%tid",
                           "pid": "${PID:-}",
                           "thread": "%thread",
                           "class": "%logger{1.}:%L",
                           "message": "%message",
                           "stackTrace": "%exception{10}"
                           }
                       </pattern>
                   </pattern>
               </providers>
           </encoder>
       </appender>
   
   </configuration>
   
   ```
    Thans anyway.
   
   
   
   
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services