Gorm / Grails 中域类的环境过滤器/拦截器?

发布于 2024-10-07 08:16:18 字数 865 浏览 0 评论 0原文

我刚刚为我的 Grails 系统集成了一个日志记录概念,并使用过滤器机制来记录对我的控制器和操作的访问。好处是我可以为所有控制器和操作定义一个过滤器。

对于域类,我只知道拦截器概念,我必须为每个单独的域类编写一个拦截器。是否有类似于域类过滤器的概念,我可以在其中为所有域类定义拦截器?

预先非常感谢, 约尔格.

更新1: 感谢您提供有关 Stefan 的审核日志插件的提示。审核日志记录插件看起来是最简单的替代方案,但根据我的口味生成了太多行/日志,并且不使用 grails/log4j 日志记录系统。

目前,我的要求是:

  1. 记录所有域类的插入/更新/删除(以便仅记录事件,而不是每个字段/列的每次更改)

  2. 记录到 Grails 日志记录系统 (log4j),以便记录到 stdout、单个数据库表或电子邮件(该级别可能例如,INFO 或 TRACE)

  3. Log到一个特殊的域类(数据库表),以便在其之上构建日志可视化/管理系统(通过 Grails 控制器和操作)。在这里,如果日志位于同一个或另一个数据库/grails-app 中,最好进行配置(以便稍后拆分日志管理系统)。

据我所知,可以通过以下方式完成简单的“更改”日志记录:

  1. 域类中的单独日志语句(需要每个域类中的插入/更新/删除事件)

  2. 定义一个继承插入/更新/删除事件的“日志”超类(使得很难在特殊域类中创建单独的插入/更新/删除事件)

  3. 为所有控制器定义一个过滤器,但仅保存/更新/删除操作(问题:不记录对没有控制器的域类的更改,或者如果在一个操作中触及多个域类)

希望这对其他人有帮助。尽管如此,我错过了什么吗?

I just integrated a logging concept for my Grails system and used the filter mechanism to log access to my controllers and actions. The good thing is that I can define one filter for all controller and actions.

With domain classes I do only know the interceptor concept where I have to write an interceptor for every individual domain class. Is there a concept similar to filters for domain classes where I can define an interceptor for ALL domain classes?

Many thanks in advance,
Joerg.

UPDATE 1:
Thank you for the tip on the Audit Logging Plugin by Stefan. The Audit Logging Plugin looks like the easiest alternative but produces too many rows/logs for my taste and does not use the grails/log4j logging system.

Currently, my requirements are:

  1. Log the insert/update/delete for all domain classes (in order to log only the incidents, not every change to every field/column)

  2. Log to the Grails logging system (log4j) in order to log to stdout, individual database tables, or email (The level might be, e.g., INFO or TRACE)

  3. Log to a special domain class (db table) in order to build a log visualization / management system on top of it (via Grails controller & actions). Here it would be great to configure if the logs are in the same or another database/grails-app (in order to split the log management system later on).

As far as I know a simple "change" logging can be done via:

  1. Individual log statements in domain classes (requires insert/update/delete events in every domain class)

  2. Define a "Log" Superclass which inherits the insert/update/delete events (makes it hard to make indivudal insert/update/delete events in special domain classes)

  3. Define a Filter for all controllers but only save/update/delete actions (problem: does not log changes to domain classes without an controller or if multiple domain classes are touched in one action)

Hope this helps other. Nevertheless, Did I miss something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

素手挽清风 2024-10-14 08:16:18

也许 http://www.grails.org/plugin/audit-logging 就是你的正在寻找。

Maybe http://www.grails.org/plugin/audit-logging is what you're looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文