简体   繁体   English

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

[英]Ambient filter / interceptors for domain classes in Gorm / Grails?

I just integrated a logging concept for my Grails system and used the filter mechanism to log access to my controllers and actions. 我只是为Grails系统集成了日志记录概念,并使用了过滤器机制来记录对控制器和操作的访问。 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. 预先非常感谢,Joerg。

UPDATE 1: Thank you for the tip on the Audit Logging Plugin by Stefan. 更新1:感谢您提供有关Stefan的Audit Logging插件的提示。 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. Audit Logging插件看起来是最简单的替代方法,但是根据我的喜好会生成太多的行/日志,并且不使用grails / log4j日志系统。

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, eg, INFO or TRACE) 登录到Grails日志记录系统(log4j),以便登录到stdout,单个数据库表或电子邮件(级别可能是,例如INFO或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). 登录到特殊的域类(数据库表),以便在其之上构建日志可视化/管理系统(通过Grails控制器和操作)。 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). 在这里,最好配置日志是在同一数据库中还是在另一个数据库/ grails-app中(以便以后拆分日志管理系统)。

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? 但是,我错过了什么吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM