开发者

Log4J at Request Scope

Before writing this query, I reviewed similar queries at:

  • Log4j: One log file per request
  • Log TraceNo for each request in web application using Log4j

I felt 开发者_JAVA技巧my query sounds similar but not the same.

Did you ever come across grouping of log messages on request entry and flush them on response close. i.e. the sequence of operations expected would be as below:

  1. configure the Logger to request scope.
  2. server receives request.
  3. logs written by each of the context beans be buffered by request scoped logger.
  4. response prepared, flushed and closed.
  5. logger gets notified that response is complete.
  6. now logger writes the buffered messages as a batch to associated appender and then clears its buffer.

I am looking for such a possibility with currently available log4j implementation.

Please share your opinions.


include request id into log (you may use log4j's NDC). sort log file by this id and by timestamp.

i think it's wrong, to record events in the order, different from their original order. This may lead to a a very big confusion.


I usually don't group logs by request because a conversation is longer than a single request. So my solution is to add the user name to log4j's MDC.

That way, I can for example create one log file per user or see all the requests which were made by a user (plus the responses and all the code that was executed on the user's behalf outside of the requests, for example when background jobs are started).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜