-
Notifications
You must be signed in to change notification settings - Fork 125
Description
I'm trying to use Flogger with SLF4J+Logback as a backend so that I can output structured logs using logstash-logback-encoder. With the SLF4J API, I can add structured attributes to log statements that can be parsed and efficiently searched.
I want to use the Flogger API for this, so I can take advantage of rate-limiting logging. It looks like flogger's with(MetadataKey, Value) would be a good fit for this. However, it seems the SFL4J-backend doesn't pass the Metadata into the SLF4J's LogEvent, but instead directly appends it to the log message. Would it be possible to pass Flogger's metadata to SLF4J and let the logging configuration choose how to format it?
Here are some concrete examples of what I'm trying to achieve in Logback and what I get with flogger:
Logback Key-value as attributes
logback.atDebug().addKeyValue("key", "value").log("Logback with key values");
{"t":"2025-04-06T16:37:25","s":"INFO", "msg":"Logback with key values","attr":{"key":"value"}}Logback Marker as attributes
if (testLogBack.isDebugEnabled())
logback.atDebug().addMarker(append("key", "value")).log("Logback with marker");
{"t":"2025-04-06T16:37:07","s":"INFO", "msg":"Logback with marker","attr":{"key":"value"}}Flogger MetaData gets appended to the formatted message
flogger
.atFine()
.with(MetadataKey.single("key", String.class), "value")
.log("Flogger with key values");
{"t":"2025-04-06T16:37:25","s":"INFO", "msg":"Flogger with key values [CONTEXT key=\"value\" ]"}