如何系统地添加(修饰)一些数据以记录日志 [英] How to systematically add (decorate) some data to log
问题描述
我对如何解决这个问题有一些想法:
- 为log4j patternLayout添加自定义字段
- 使用groovy的meta-class设施拦截每个日志调用和修改消息内容
我只想拥有易于理解和维护的内容:这是一个非常低的优先级功能,所以我不想花费太麻烦了。
任何有关快速简便的方法来实现这个建议?
我认为Burt Beckwith在他的博客上介绍了 在一月。他展示了如何使用log4j MDC功能和Servlet Filter来将用户名输入日志条目中。
In a grails application I want to decorate each logs with custom data. The current need is simply to prepends the current user name to the log message
I've some idea about how to resolve this issue:
- Adding custom field to log4j patternLayout
- Using groovy's meta-class facilities to intercept each log call and modify the message content
I just want to have something easy to understand and to maintain: this is a very low priority feature so I don't want spending too much time messing around with it.
Any suggestion about a fast and easy way to implement this ?
I think Burt Beckwith covered this on his blog back in January. He shows how to use the log4j MDC functionality and a Servlet Filter to get the username into the log entries
这篇关于如何系统地添加(修饰)一些数据以记录日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!