0

We are using grails audit logging plugin for auditing few domain objects in our project https://grails.org/plugin/audit-logging

Facing couple of issues related to it:

  1. We have a user domain object which we want to audit. We also create lot of users during our system set up. So, when we make auditable = true for User domain, it audits that as well - creates a new row in audit_log_event table for each user that gets created.

    Is there a way to avoid this? We just want to audit when a user is created/updated by an admin user (basically when the admin user is logged in)

  2. For some of the attributes of a domain object that we are auditing, we want to make some modification in the new value. Example: Lets say email address of User object is getting updated from a@gmail.com to b@gmail.com, then we want to insert "***B@gmail.com-12:23:47" in new_value column of audit_log_event table.

    I thought by updating the value of newMap[key] in onChange() method, we can do this, but that doesn't seem to work. Is there a way to do this?

    Tried this:

def onChange = {
           oldMap,newMap ->
              println "User was changed ..."

              oldMap.each({ key, oldVal ->
                 if(oldVal != newMap[key]) {
                    println " * $key changed from $oldVal to " + newMap[key]

                    if(key == "email") {
                        newMap[key] = "*****Some value udpated****"
                        println "email is now again changed ..."
                        println " * $key changed from $oldVal to " + newMap[key]
                    }
                 }
              })
}

Console output:

   User was changed ...
    * email changed from a@gmail.com to b@gmail.com
   email is now again changed ...
    * email changed from a@gmail.com to *****Some value udpated****

However, in DB:

old_value = a@gmail.com
new_value = b@gmail.com
Rao
  • 20,781
  • 11
  • 57
  • 77
user1270392
  • 2,981
  • 4
  • 21
  • 25
  • 1. For this, you can use the withoutAuditLog `closure:AuditLogListener.withoutAuditLog { ... your bulk stuff }` 2. Use the GORM beforeInsert() / beforeUpdate methods. – Bertl Nov 08 '16 at 11:06
  • Thanks @Bertl 1) I used the closure like below in one the class that I want to audit (Person.groovy). Tried to make use of AuditLogListenerThreadLocal.auditLogDisabled, but that didn't work. Its still auditing even though it prints the log statement. Am sure doing something wrong in the way we need to use the closure or threadlocal variable. def onChange = { if(!loggedIn) { log.error("non logged in user, skip audting") AuditLogListener.withoutAuditLog { AuditLogListenerThreadLocal.auditLogDisabled = true } } } – user1270392 Nov 10 '16 at 07:06
  • 2) Sorry, didn't ask my question very well. Basically, the issue is related to embedded object. This link explains the question better. https://github.com/robertoschwald/grails-audit-logging-plugin/issues/111 – user1270392 Nov 10 '16 at 07:06

0 Answers0