You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by "shichaoyuan (via GitHub)" <gi...@apache.org> on 2025/11/26 04:14:36 UTC

[I] [Bug] The `replaceParam` method of `AbstractLogger` behaves unexpectedly when the replaced string contains a replacement marker [skywalking]

shichaoyuan opened a new issue, #13591:
URL: https://github.com/apache/skywalking/issues/13591

   ### Search before asking
   
   - [x] I had searched in the [issues](https://github.com/apache/skywalking/issues?q=is%3Aissue) and found no similar issues.
   
   
   ### Apache SkyWalking Component
   
   Java Agent (apache/skywalking-java)
   
   ### What happened
   
   The `replaceParam` method of `AbstractLogger` behaves unexpectedly when the replaced string contains a replacement marker.
   
   
   
   
   ### What you expected to happen
   
   ```
   log.info("sample rule update: {} -> {}", "Config{a={}}", "Config{b={}}")
   ```
   
   expect:  sample rule update: Config{a={}} -> Config{b={}}
   
   but actual: sample rule update: Config{a=Config{b={}}} -> {}
   
   ### How to reproduce
   
   just run code above
   
   ### Anything else
   
   https://github.com/apache/skywalking-java/blob/67ab8b222fbb9a71b450665eb9f733380d813b8a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/logging/core/AbstractLogger.java#L185-L203
   
   
   ```
               tmpMessage = tmpMessage.replaceFirst("\\{\\}", Matcher.quoteReplacement(String.valueOf(parameters[parametersIndex++])));
               startSize = index + 2;
   ```
   
   The `index` should not just increase by 2, but should increase by the length of the string to be replaced.
   
   
   
   ### Are you willing to submit a pull request to fix on your own?
   
   - [x] Yes I am willing to submit a pull request on my own!
   
   ### Code of Conduct
   
   - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct)
   


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

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] The `replaceParam` method of `AbstractLogger` behaves unexpectedly when the replaced string contains a replacement marker [skywalking]

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on issue #13591:
URL: https://github.com/apache/skywalking/issues/13591#issuecomment-3579143405

   We don't want to use complex regex to be honest.
   Why we need to put agent logs so complex? It should be just a simple version implementation, as agent plugin is the only one using it.
   This is not an app logger.


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

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] The `replaceParam` method of `AbstractLogger` behaves unexpectedly when the replaced string contains a replacement marker [skywalking]

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng closed issue #13591: [Bug] The `replaceParam` method of `AbstractLogger` behaves unexpectedly when the replaced string contains a replacement marker
URL: https://github.com/apache/skywalking/issues/13591


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

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] The `replaceParam` method of `AbstractLogger` behaves unexpectedly when the replaced string contains a replacement marker [skywalking]

Posted by "shichaoyuan (via GitHub)" <gi...@apache.org>.
shichaoyuan commented on issue #13591:
URL: https://github.com/apache/skywalking/issues/13591#issuecomment-3579277026

   > We don't want to use complex regex to be honest. Why we need to put agent logs so complex? It should be just a simple version implementation, as agent plugin is the only one using it. This is not an app logger.
   
   I fully agree with your point. Regular expressions are unnecessary here, simple string replacement would suffice for implementation.
   
   ```java
       protected String replaceParam(String message, Object... parameters) {
           if (message == null) {
               return message;
           }
           int startSize = 0;
           int parametersIndex = 0;
           int index;
           StringBuilder sb = new StringBuilder(message);
           while ((index = sb.indexOf("{}", startSize)) != -1) {
               if (parametersIndex >= parameters.length) {
                   break;
               }
   
               String tmp = String.valueOf(parameters[parametersIndex++]);
               sb.replace(index, index+2, tmp);
               startSize = index + tmp.length();
           }
           return sb.toString();
       }
   ```


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

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] The `replaceParam` method of `AbstractLogger` behaves unexpectedly when the replaced string contains a replacement marker [skywalking]

Posted by "wu-sheng (via GitHub)" <gi...@apache.org>.
wu-sheng commented on issue #13591:
URL: https://github.com/apache/skywalking/issues/13591#issuecomment-3579634503

   Could you explain more about which is the bug now? Or file a PR to show the code change without using regex.


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

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] The `replaceParam` method of `AbstractLogger` behaves unexpectedly when the replaced string contains a replacement marker [skywalking]

Posted by "shichaoyuan (via GitHub)" <gi...@apache.org>.
shichaoyuan commented on issue #13591:
URL: https://github.com/apache/skywalking/issues/13591#issuecomment-3580006999

   > Could you explain more about which is the bug now? Or file a PR to show the code change without using regex.
   
   I submitted a PR https://github.com/apache/skywalking-java/pull/782


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

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org