Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logback-appender-1.0's captureKeyValuePairAttributes implementation lost value type #10776

Closed
qixiaogang opened this issue Mar 7, 2024 · 1 comment · Fixed by #10781
Closed
Labels
enhancement New feature or request

Comments

@qixiaogang
Copy link

qixiaogang commented Mar 7, 2024

Describe the bug

Current logback-appender-1.0's captureKeyValuePairAttributes implementation lost value type when converting KeyValuePair to attributes

  private static void captureKeyValuePairAttributes(
      AttributesBuilder attributes, ILoggingEvent loggingEvent) {
    List<KeyValuePair> keyValuePairs = loggingEvent.getKeyValuePairs();
    if (keyValuePairs != null) {
      for (KeyValuePair keyValuePair : keyValuePairs) {
        if (keyValuePair.value != null) {
          attributes.put(getAttributeKey(keyValuePair.key), keyValuePair.value.toString());
        }
      }
    }
  }

Steps to reproduce

when logging as below using slf4j

        logger.atInfo().setMessage("This is a test for keyValue")
                .addKeyValue("string", "stringValue")
                .addKeyValue("double", 10.1)
                .addKeyValue("long", 10)
                .addKeyValue("boolean", true)
                .log();

and then configure logback appender 1.0 with captureKeyValuePairAttributes=true

Expected behavior

Expect attributes of key boolean, double, long, and string as below
{boolean=true, double=10.1, long=10, string="stringValue", ...}

Actual behavior

while attributes of key boolean, double, long, and string as below
{boolean="true", double="10.1", long="10", string="stringValue", ...}

Javaagent or library instrumentation version

2ee4ee1

Environment

JDK:
OS:

Additional context

No response

@qixiaogang qixiaogang added bug Something isn't working needs triage New issue that requires triage labels Mar 7, 2024
@steverao steverao added enhancement New feature or request and removed bug Something isn't working needs triage New issue that requires triage labels Mar 8, 2024
@qixiaogang
Copy link
Author

@laurit @steverao thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants