如何在 Log4J 中记录指定框架类的输出
我需要将特定 Spring 类(org.springframework.core.log.LogFormatUtils)的输出记录到给定的附加程序(最后是 Graylog,但我使用 FileAppender 进行测试 - 这里并不重要)。 我知道,一般来说,这可以通过使用来完成
<Loggers>
<Logger name="org.springframework.core.log.LogFormatUtils" level="DEBUG">
<AppenderRef ref="FileAppender"/>
</Logger>
<Root level="debug" includeLocation="true">
<AppenderRef ref="ConsoleAppender"/>
</Root>
</Loggers>
,但是,这不起作用 - 它不输出任何内容。如果我将记录器的名称/包引用更改为“org.springframework”,它会按预期工作,但我对以这种方式出现的一堆信息不感兴趣。此外,如果我表示类似 com.myapp.mypackage 的内容,它也可以工作。 那么,在我可以记录 Spring 框架输出之前,是否需要执行一些注意事项或步骤?
I need to log the output of a specific Spring class (org.springframework.core.log.LogFormatUtils) to a given appender (Graylog in the end, but I used a FileAppender for testing purposes - doesn't matter here).
I'm aware that generally, this could be done quite simple by using
<Loggers>
<Logger name="org.springframework.core.log.LogFormatUtils" level="DEBUG">
<AppenderRef ref="FileAppender"/>
</Logger>
<Root level="debug" includeLocation="true">
<AppenderRef ref="ConsoleAppender"/>
</Root>
</Loggers>
However, this does not work - it outputs nothing. If I change the logger's name / package reference to "org.springframework" it works as expcted, but I'm not interested in the bunch of inforamtion coming along that way. Additionally, if I denote something like com.myapp.mypackage, it also works.
So, are there some caveats or steps to perform before I can log Spring framework output in general?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该方法是
LogFormatUtils
类中唯一使用Log对象的方法,但是它使用的Log对象是从其他类传递过来的,也就是说Log对象的logger name不是>org.springframework.core.log.LogFormatUtils
,您可以将logger的名称更改为org.springframework
,并将%logger
添加到PatternLayout中以查找真实的logger名称你 需要。The method is the only method in the
LogFormatUtils
class that uses the Log object, but the Log object it uses is passed from other classes, that is to say, logger name of the Log object is notorg.springframework.core.log.LogFormatUtils
, you can change logger's name toorg.springframework
and add%logger
to PatternLayout to find the real logger's name you need.