'Audit
@param method: Method to log, one of
"create", "update", "read", "list" or "delete"
@param prefix: the module prefix of the resource
@param name: the name of the resource (without prefix)
@param form: the form
@param record: the record ID
@param representation: the representation format'

def __call__(self, method, prefix, name, form=None, record=None, representation='unknown'):

    table = self.table
    if (not table):
        return True
    if (method in ('list', 'read')):
        audit = current.deployment_settings.get_security_audit_read()
    elif (method in ('create', 'update', 'delete')):
        audit = current.deployment_settings.get_security_audit_write()
    else:
        return True
    if (not audit):
        return True
    tablename = ('%s_%s' % (prefix, name))
    if record:
        if isinstance(record, Row):
            record = record.get('id', None)
            if (not record):
                return True
        try:
            record = int(record)
        except ValueError:
            record = None
    elif form:
        try:
            record = form.vars['id']
        except:
            try:
                record = form['id']
            except:
                record = None
        if record:
            try:
                record = int(record)
            except ValueError:
                record = None
    else:
        record = None
    if callable(audit):
        audit = audit(method, tablename, form, record, representation)
        if (not audit):
            return True
    if (method in ('list', 'read')):
        table.insert(timestmp=datetime.datetime.utcnow(), user_id=self.user_id, method=method, tablename=tablename, record_id=record, representation=representation, repository_id=current.response.s3.repository_id)
    elif (method == 'create'):
        if form:
            form_vars = form.vars
            if (not record):
                record = form_vars['id']
            new_value = [('%s:%s' % (var, str(form_vars[var]))) for var in form_vars if form_vars[var]]
        else:
            new_value = []
        table.insert(timestmp=datetime.datetime.utcnow(), user_id=self.user_id, method=method, tablename=tablename, record_id=record, representation=representation, new_value=new_value, repository_id=current.response.s3.repository_id)
    elif (method == 'update'):
        if form:
            rvars = form.record
            if rvars:
                old_value = [('%s:%s' % (var, str(rvars[var]))) for var in rvars]
            else:
                old_value = []
            fvars = form.vars
            if (not record):
                record = fvars['id']
            new_value = [('%s:%s' % (var, str(fvars[var]))) for var in fvars]
        else:
            new_value = []
            old_value = []
        table.insert(timestmp=datetime.datetime.utcnow(), user_id=self.user_id, method=method, tablename=tablename, record_id=record, representation=representation, old_value=old_value, new_value=new_value, repository_id=current.response.s3.repository_id)
    elif (method == 'delete'):
        db = current.db
        query = (db[tablename].id == record)
        row = db(query).select(limitby=(0, 1)).first()
        old_value = []
        if row:
            old_value = [('%s:%s' % (field, row[field])) for field in row]
        table.insert(timestmp=datetime.datetime.utcnow(), user_id=self.user_id, method=method, tablename=tablename, record_id=record, representation=representation, old_value=old_value, repository_id=current.response.s3.repository_id)
    return True
