我已将audit-logging
插件安装到我的应用程序中。grails 版本是2.1.1
,插件版本是1.0.1
.
在我的Config.groovy
课堂上,我添加了这个
auditLog {
verbose = true // verbosely log all changed values to db
logIds = true // log db-ids of associated objects.
// Note: if you change next 2 properties, you must update your database schema!
tablename = 'audit_logs' // table name for audit logs.
transactional = false
actorClosure = { request, session ->
org.apache.shiro.SecurityUtils.getSubject()?.getPrincipal()
}
在我的域类中,我添加了这个
class Survey {
static auditable = true
static final int NO_RUNNING_SURVERY = 0
static final int RUNNING_SURVERY = 1
static final int CALL_NO_Record_SURVEY = 0
static final int CALL_Record_SURVEY = 1
static final int REALTIME_SURVEY = 0
static final int HISTORICAL_SURVEY = 1
static final int STANDARD_SURVERY = 2
String name
String description
int status
}
当我添加、删除和更新一些东西时。在我的audit_logs
表中,针对一项操作插入双记录,例如,如果我从控制器类更改状态值
def stopSurvey(Long id) {
def survey = Survey.findById(params['stop'])
survey.status = Survey.NO_RUNNING_SURVERY
redirect(action: "list")
}
它每次调用插入两条记录。