How do you differentiate log4j sessions in a log file from copies of the same web-app?

后端 未结 4 1425
滥情空心
滥情空心 2021-01-05 04:35

There is only one file. And it is written simultaneously as web app copies run.

How do you filter only one session log messages from other log lines?

4条回答
  •  醉话见心
    2021-01-05 04:49

    If you want to differentiate sessions in the same application then the MDC is the way to go. But if you want to differentiate the web applications writing to the same file, then MDC won't help because it works on a thread basis. In such case I used to make my own appender which knows which application instance it serves. This can be done through appender configuration properties. Such appender would stick application name into each logging event as a property before writing it into the media, and then you can use a layout to show this property value in the text file it writes to. Using MDC in such case won't work because every thread will have to MDC.put(applicationName) and that is quite ugly. MDC is only good for single process, not for several processes. If someone knows the other way, I'd like to hear.

提交回复
热议问题