Log4j:每个请求一个日志文件 [英] Log4j: One log file per request

查看:543
本文介绍了Log4j:每个请求一个日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个weblogic批处理应用程序,可以同时处理来自消费者的多个请求。我们使用log4j来记录目的。现在我们为多个请求登录一个日志文件。调试给定请求的问题与日志在单个文件中的所有请求一样变得冗长乏味。

We have a weblogic batch application which processes multiple requests from consumers at the same time. We use log4j for logging puposes. Right now we log into a single log file for multiple requests. It becomes tedious to debug an issue for a given request as for all requests the logs are in a single file.

所以计划是每个请求有一个日志文件。消费者发送必须执行处理的请求ID。现在,实际上可能有多个消费者将请求ID发送到我们的应用程序。所以问题是如何根据请求分割日志文件。

So plan is to have one log file per request. The consumer sends a request ID for which processing has to be performed. Now, in reality there could be multiple consumers sending the request IDs to our application. So question is how to seggregate the log files based on the request.

我们无法启动&每次都停止生产服务器,因此排除了使用带有日期时间戳或请求ID的重写文件appender的要点。这就是下面的文章中解释的:
http://veerasundar.com/blog/2009/08/how-to-create-a-new-log-file-for-each-time -the-application-runs /

We cannot start & stop the production server every time so the point in using an overridden file appender with date time stamp or request ID is ruled out. This is what is explained in the article below: http://veerasundar.com/blog/2009/08/how-to-create-a-new-log-file-for-each-time-the-application-runs/

我也试过玩这些替代品:

I also tried playing around with these alternatives:

http://cognitivecache.blogspot。 com / 2008/08 / log4j-writing-to-dynamic-log-file-for.html

http://www.mail-archive.com/log4j-user@logging.apache.org/ msg05099.html

此方法可提供所需的结果,但如果同时发送多个请求,则无法正常运行。由于一些并发问题,日志会在这里和那里发生。

This approach gives the desired results but it does not work properly if multiple request are send at the same time. Due to some concurrency issues logs go here and there.

我期待你们的帮助。在此先感谢....

I anticipate some help from you folks. Thanks in advance....

推荐答案

以下是关于同一主题的问题:
动态创建&销毁日志记录附加程序

Here's my question on the same topic: dynamically creating & destroying logging appenders

我在Log4J邮件列表上讨论做类似这样的事情的一个帖子中跟进了这个:
http://www.qos.ch/pipermail/logback-user/ 2009年8月/ 001220.html

I follow this up on a thread where I discuss doing something exactly like this, on the Log4J mailing list: http://www.qos.ch/pipermail/logback-user/2009-August/001220.html

Ceci Gulcu(log4j的发明者)认为这不是一个好主意......建议使用Logback代替。

Ceci Gulcu (inventor of log4j) didn't think it was a good idea...suggested using Logback instead.

我们继续使用自定义文件appender完成此操作。有关详细信息,请参阅上面的讨论。

We went ahead and did this anyway, using a custom file appender. See my discussions above for more details.

这篇关于Log4j:每个请求一个日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆