请求范围内的 Log4J

发布于 2024-12-08 19:21:32 字数 637 浏览 0 评论 0原文

在编写此查询之前,我查看了类似的查询:

我觉得我的查询听起来相似但不一样。

您是否曾经遇到过在请求输入时对日志消息进行分组并在响应关闭时刷新它们。即预期的操作顺序如下:

  1. 配置记录器以请求范围。
  2. 服务器接收请求。
  3. 每个上下文 bean 写入的日志由请求范围记录器缓冲。
  4. 响应已准备好、刷新并关闭。
  5. 记录器收到响应已完成的通知。
  6. 现在记录器将缓冲的消息批量写入关联的附加程序,然后清除其缓冲区。

我正在寻找当前可用的 log4j 实现的这种可能性。

请分享您的意见。

Before writing this query, I reviewed similar queries at:

I felt 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

忆梦 2024-12-15 19:21:32

将请求 ID 包含到日志中(您可以使用 log4j 的 NDC)。按此 ID 和时间戳对日志文件进行排序。

我认为按照与原始顺序不同的顺序记录事件是错误的。这可能会导致一个非常大的混乱。

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.

你的笑 2024-12-15 19:21:32

我通常不会按请求对日志进行分组,因为对话比单个请求长。所以我的解决方案是将用户名添加到 log4j 的 MDC< /a>.

这样,我可以为每个用户创建一个日志文件,或者查看用户发出的所有请求(加上响应以及在请求之外代表用户执行的所有代码,例如当后台作业时)开始)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文