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:
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)
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