java - Log4j2 KeyValue Pairs - Stack Overflow

admin2025-04-17  4

Coming from the SLF4j world, I'm used to being able to use this syntax (via the Logstash encoder library) to provide key/value pairs:

MY_SLF4J_LOGGER.info("I'm processing a file", kv("file-id", 1234), kv("line-number", 42));

I know that Log4j2 supports key/value pairs via the MDC and via map-based logging, but is there a way to provide key/value pairs on a single log statement like the above SLF4j example? (Adding something to the MDC for a single log statement seems like overkill for a lot of my use cases.)

转载请注明原文地址:http://anycun.com/QandA/1744900087a89208.html