I'm using log4j2, and running multiple instances of the same code in different processes (ie different JVMs) at the same time. I'd like all processes to log to the same file, interleaved How can I configure (via log4j2.xml) to output the PID, so that the different processes can be distinguished in the logs?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Perhaps MDC can help you. Try this:
Java:
XML:
Output:
You may want to see:
There is a plugin ProcessIdPatternConverter in log4j2-core since version 2.9 that does exactly this.
just setting %pid or %processId in the pattern layout logs it.
log4j documentation: https://logging.apache.org/log4j/2.x/manual/layouts.html