evanxuhe opened a new pull request #3219: Log4j2 support AsyncRoot print tid
URL: https://github.com/apache/skywalking/pull/3219
 
 
   Please answer these questions before submitting pull request
   
   - Why submit this pull request?
   - [ ] New feature provided
   
   
   ___
   ### New feature or improvement
   #### New feature
   Log4j2 support AsyncRoot print tid 
   Just refer to the idea from  Logback AsyncAppenderRoot
   
   #### Test App
   I have build a simple SpringMVC web app to test log4j2 <Root> and 
<AsyncRoot> individually.
   And it works well as the photo
   
![image](https://user-images.githubusercontent.com/24379174/62447819-d6502780-b798-11e9-82d1-4a6add4f27db.png)
   
   #### Question
   ##### 1. Is it ok to delete 2 classes that intercepts  Log4jOutputAppender 
before? ↓
   ```Log4j2OutputAppenderActivation```  ```PrintTraceIdInterceptor```(code 
pasted to the end)
   I am not quite sure why adds Log4j2OutputAppender, which seems redundant. 
And i notice it is designed as a static method, is that from the idea that 
avoids OOM ?
   What's more I just delete these 2 files,  because all i need is the format 
method in TraceIdConverter, whose 1st param is the enhanced Log4jLogEvent that 
carrys tid info. I am not sure if it obeys your origin design. Waiting for your 
reply.
   
   #### 2. How to design test?
   I am not quite sure how to design the test scenerio for this. :)
   
   
   ```java
   @Plugin(name = "TraceIdConverter", category = "Converter")
   @ConverterKeys({"traceId"})
   public class TraceIdConverter extends LogEventPatternConverter {
   
       /**
        * Constructs an instance of LoggingEventPatternConverter.
        *
        * @param name name of converter.
        * @param style CSS style for output.
        */
       protected TraceIdConverter(String name, String style) {
           super(name, style);
       }
   
       public static TraceIdConverter newInstance(String[] options) {
           return new TraceIdConverter("traceId", "traceId");
       }
   
       @Override
       public void format(LogEvent event, StringBuilder toAppendTo) {
           Log4j2OutputAppender.append(toAppendTo);
       }
   }
   ```
   ```java
   public class Log4j2OutputAppender {
       /**
        * As default, append "TID: N/A" to the output message,
        * if sky-walking agent in active mode, append the real traceId in the 
recent Context, if existed, or empty String.
        *
        * @param toAppendTo origin output message.
        */
       public static void append(StringBuilder toAppendTo) {
           toAppendTo.append("TID: N/A");
       }
   }
   ```

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


With regards,
Apache Git Services

Reply via email to