log4j:将特定类的输出记录到特定的附加程序
我使用 log4j 并希望将某些记录器的输出路由到特定文件。
我已经有多个附加程序了。现在,为了使调试更容易,我想告诉 log4j 由特定类(例如 foo.bar.Baz)生成的输出应该写入特定的日志文件。
这可以做到吗?
I use log4j and would like to route the output of certain Loggers to specific files.
I already have multiple appenders in place. Now, to make debugging easier, I want to tell log4j that the output generated by a specific class (e.g. foo.bar.Baz) should be written to a specific log file.
Can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个例子:
An example:
这是关于 XML 配置的答案,请注意,如果您没有为文件附加程序提供
ConversionPattern
,它将创建 0 字节文件并且不写入任何内容:Here's an answer regarding the XML configuration, note that if you don't give the file appender a
ConversionPattern
it will create 0 byte file and not write anything:下面是一个将详细信息记录到单独文件中的示例,每个月推出文件并删除超过 180 天的日志:
如果您希望将某个类的日志记录到单独的文件中,例如
auditlogger
,请使用它在一个类中如下:Here is an example for logging details into separate files, rollout file for every month and delete logs older than 180 days:
Here if you wish to have logs from some class into separate file, like
auditlogger
then use it inside a class as follows: