Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4j2: Include PID

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?

like image 686
SRobertJames Avatar asked Sep 09 '14 23:09

SRobertJames


1 Answers

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

like image 100
Ricard Nàcher Roig Avatar answered Sep 28 '22 15:09

Ricard Nàcher Roig