Reputation: 1461
I am using slf4j. I have lots of log statements that look like this;
LOG.debug("I like {} and {}", new Object[] { "foo", "bar" });
When this log statement is executed, I get logs that look like this;
I like foo and bar
As expected. However, I would like log message parameters to have additional formatting, to make it much easier for log parsers. An desired log message that literally looks like this;
I like [foo] and [bar]
Obviously I could update the literal log statement to I like [{}] and [{}]
, but this is a lot of change, makes the log statements look unessessarily messy and isn't very flexible for the future.
Could somebody suggest a quicker solution while still keeping with slf4j? The implementation I am using is logback-classic to do the actual lgoging.
Thanks!
Upvotes: 1
Views: 91
Reputation: 40036
If you are using Logback, probably you can construct a custom appender/encoder/layout/converter. In Logback, Appenders are taking in LoggingEvent, which normally delegates to an encoder for which delegate to a layout to construct the message. Have a look on the source code to see which part is the best place for you to do the custom handling.
Upvotes: 1