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

后端 未结 4 1394
滥情空心
滥情空心 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 05:09

    You could set a context message including the identifier of the specific app instance using org.apache.log4j.NDC, like this:

    String appInstanceId = "My App Instance 1";
    org.apache.log4j.NDC.push(appInstanceId);
    // handle request
    org.apache.log4j.NDC.clear();
    

    You can set up the context during the initialization of your web app instance, or inside the doPost() method of your servlets. As its name implies, you can also nest contexts within contexts with multiple push calls at different levels.

    See the section "Nested Diagnostic Contexts" in the Log4J manual.

提交回复
热议问题