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 2018/04/09 15:44:29 UTC

[GitHub] candyleer opened a new issue #1055: log toolkit may do not take effect in some case

candyleer opened a new issue #1055: log toolkit may do not take effect in some case 
URL: https://github.com/apache/incubator-skywalking/issues/1055
 
 
   Please answer these questions before submitting your issue.
   
   - Why do you submit this issue?
   - [ ] Question or discussion
   - [x] Bug
   - [ ] Requirement
   - [ ] Feature or performance improvement
   
   ___
   ### Question
   - What do you want to know?
   
   ___
   ### Bug
   - Which version of SkyWalking, OS and JRE?
   
   - Which company or project?
   
   - What happen?
   #### Question
    when i start an app (called `test_app`) in IDE,i configure the logback file by following this [instruction](https://github.com/apache/incubator-skywalking/blob/master/docs/en/Application-toolkit-logback-1.x.md),but i found it didn't take effect.
   i debug this question step by step in `agent` jar. i found the class `org.apache.skywalking.apm.toolkit.log.logback.v1.x.TraceIdPatternLogbackLayout` didn't been transformed.this seems to be strange.what is it happened?
   then  i put an `break point` in this place, 
   ![image](https://user-images.githubusercontent.com/11530760/38506954-e09e8a0a-3c4d-11e8-9694-b6bcee17320b.png)
   and see the `debug` stack trace in ide ,Suddenly I understand.
   ![image](https://user-images.githubusercontent.com/11530760/38507096-246a5dae-3c4e-11e8-98a0-76d6dd81edc8.png)
   from this picture, we can see that the `TraceIdPatternLogbackLayout` class was loaded in `premain` method,and invoke by `boot` method.but at that time,the `byte buddy instrument` didn't work.because the code is
   ```
   ...
    ServiceManager.INSTANCE.boot();
   ...
    new AgentBuilder.Default()...
   .installOn(instrumentation);
   ```
   that is the class `TraceIdPatternLogbackLayout` loaded is before `instrumentation`.
   **this only happens when application code is loaded by `AppClassLoader`,because the `logback.xml` in this classpath.**
   
   in other cases,this code work fine cause their classloader is redefined like `spring boot` or `tomcat` etc. in this cases,the class `TraceIdPatternLogbackLayout` will be loaded only by app code invoke `logger` ,when `agent` started by `AppClassLoader`,it can not see the `logback.xml` config file thus he dont know the class `TraceIdPatternLogbackLayout`,
   
   #### Solution
   To resolve this problem ,the simplest way is to change the order of 
   ```
   ...
    ServiceManager.INSTANCE.boot();
   ...
    new AgentBuilder.Default()...
   .installOn(instrumentation);
   ```
   to 
   ```
   ...
    new AgentBuilder.Default()...
   .installOn(instrumentation);
   ...
    ServiceManager.INSTANCE.boot();
   ```
   that is first invoke `instrumentation` then boot all service in case of the boot service contains some method need to be enhanced.
   but i dont know if there has some other problem will be caused?
   so please check
   ___
   ### Requirement or improvement
   - Please describe about your requirements or improvement suggestions.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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