Aishwarya K
Aishwarya K

Reputation: 51

How to make my audit trail plugin work

I am in an need to use audit trail in my grails application i have tried all methods but audit log is empty is there any way to rectify it.I need to actually record operations such as insert,delete and update.

Below is what I followed:-

package audit 

class Person { 
    static auditable = true 
    String firstName 

    static constraints = { 
        firstName(nullable:true,size:0..60) 
    } 

    def onSave = { 
        println "new person inserted" 
    } 

    def onUpdate = { 
        println "person was updated" 
    } 

    def onDelete = { 
        println "person was deleted" 
    } 

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

Upvotes: 5

Views: 782

Answers (1)

dspies
dspies

Reputation: 1553

Other listservs that I check have suggested that the current audit-logging plugin is buggy, so you may just be experiencing a bug in the plugin. Also, I believe it has been forked and is actively being rewritten (http://jira.grails.org/browse/GPAUDITLOGGING), so you may not want to spend too much time with it right now.

With that said, I scaffolded a simple application with the domain you provided and the plugin did write out the println statements, but it only recorded the updates correctly in the database to the AUDIT_LOG table. The 2 inserts I attempted recorded null for both the NEW_VALUE and PROPERTY_NAME.

Grails dbconsole window

Upvotes: 0

Related Questions