How to systematically add (decorate) some data to log

为君一笑 提交于 2019-12-11 06:46:43

问题


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 ?


回答1:


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



来源:https://stackoverflow.com/questions/8413057/how-to-systematically-add-decorate-some-data-to-log

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!