Include change from value in audit trail for tag writes

We have enabled the audit log and would like to extend its functionality for tag writes.

When using system.tag.writeBlocking in Perspective, the audit trail records the new value along with the logged-in user who triggered the event. Ideally, we would also like to capture the previous value so we can see exactly what the value changed from. I assume there is no supported way to override the built-in audit logging behavior to achieve this.

As an alternative, for reference tags I could add a script that captures the old value when the tag changes and then writes a custom entry to the audit trail using system.util.audit. If I do that, is it possible to also identify which user triggered the change and include that into the log?

The user/actor is auto recorded as long as you don’t include that in your system.util.audit

image

This is true too for if a user does something that uses a binding to a tag, the user is recorded.

You could write your own common.tag.writeBlocking script in a module that does something like

def writeBlocking(*args, **kwargs):
    # Since args[0] should be your list of tags
    tagPaths = args[0]
    curValues = system.tag.readBlocking(tagPaths)
    # Go through curValues and record to audit log
    for qV, tagPaths in zip(curValues, tagPaths):
        msg = "Tag Path {} had value {}".format(tagPath, qV.value)
        system.util.audit(msg)
    # Then write tag values which get audited automatically
    system.tag.writeBlocking(args, kwargs)

This would be audited with all previous values first and then what was written to in two separate blocks of rows in your audit db. I would not suggest doing one by one (ie read, write for the first tag, and then so on) as it will kill performance.

Unfortunatley don’t think this is going to be feasible for any bidirecitonal tag bindings on UI components.

You should just historize the tag.

1 Like

Within perspective when i write to the tag it wont be a problem, then I can use system.util.audit and i think we’ll end up using that way.

But it would be handy to have the functionality directly on the tag by recording the way I would like to.

The reference tag have an event for value change, which would be fine to use except in that case I dont have any user information available it seems.

But the built in funcftionality with the audit trail do save with user, so maybe there was a way to get it.