How to systematically add (decorate) some data to

2019-08-03 02:18发布

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条回答
干净又极端
2楼-- · 2019-08-03 03:05

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

查看更多
登录 后发表回答