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

How to correctly map the payload of a log.atInfo to a structured log #451

Closed
bashout opened this issue Oct 16, 2024 · 5 comments
Closed

Comments

@bashout
Copy link

bashout commented Oct 16, 2024

I'm using logback and I believe your library would allow me to map a logs payload to the output. I'm trying to use the payload part of the log to pass an event.

Something like
log.atInfo { message = "test" payload = buildMap(capacity = 1) { put(LogEvent.Event, LogEvent.Test_Event}}

Your wiki or docs don't really clearly tell me how I can access this payload value.

Copy link

Thank you for reporting an issue. See the wiki for documentation and slack for questions.

@oshai
Copy link
Owner

oshai commented Oct 16, 2024

This might be helpful. https://www.baeldung.com/java-structured-logging

@bashout
Copy link
Author

bashout commented Oct 24, 2024

I appreciate the article, still having the same issue however. I've already configured structured logging using the logstash-logback-encoder and have a encoder pattern that pulls out things like a correlationID from the MDC for example and this is functional.

However the article suggests that any key value pair added will be automatically rendered as a structured log. Appreciate this may be a "my config" issue, but there's not a lot of clear guidance. My encoder looks like this:

{
        "timestamp": "%date{yyyy-MM-dd'T'HH:mm:ss.SSSZ}",
        "severity": "%p", 
        "exception": "%rEx",
        "logger": "%logger",
        "message": "%message",
        "correlationId": "%X{correlationId}"
}

I've tried both permutations of "log_event_code": "%X{log_event_code}" and "log_event_code": "" where the key in the payload where I log is 'log_event_code' to see if it required a placeholder, however each to no avail.

Am I missing something obvious?

@oshai
Copy link
Owner

oshai commented Oct 27, 2024

I don't think it's an issue related to kotlin-logging. You can try to debug it and see how it is decoded.

@bashout
Copy link
Author

bashout commented Nov 5, 2024

Appreciate the feedback. I'm sure you're right. I'll mark this as resolved

@bashout bashout closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants