如何系统地添加(修饰)一些数据以记录日志 [英] How to systematically add (decorate) some data to log

查看:94
本文介绍了如何系统地添加(修饰)一些数据以记录日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在grails应用程序中,我想用自定义数据来装饰每个日志。目前的需求仅仅是将当前的用户名前置到日志消息中。



我对如何解决这个问题有一些想法:

- 为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆