Logged changes to an audit log

audit log best practices
audit logs
audit log example
audit log review template
importance of audit trail
security audit log
audit trail in database
audit trail report sample

I am writing a little app and want to keep a human-readable audit log of any changes to the database (so intentionally avoiding tools which log changes as written to the database)

The code below works but it is not at all elegant. Can you come up wiht a more elegant way to implement this?

def auditdiff(set1, set2):
    new = set(set1.items())
    old = set(session[set2].items())
    diffset = dict(old ^ new) # holds what has changed
    m = {}
    for d in diffset:
        for pair in old:
            if pair[0] == d:
                m[d + " OLD"] =  pair[1]

        for pair in new:
            if pair[0] == d:
                m[d + " NEW"] = pair[1]
    return(m)

Here are examples of the variables as caught by the debugger:

set1: (old values)

<class 'dict'>: {'date': '2019-04-25', 'student_id': None, 'booking_id': '', 'key': '', 'status': 'ATTEND', 'note': 'this is a changed note', 'charge': False}

set2: (new values)

<class 'set'>: {('date', '2019-04-25'), ('note', 'this is a note'), ('student_id', None), ('charge', False), ('key', ''), ('status', 'ATTEND'), ('booking_id', '')}

diffset: (difference)

<class 'dict'>: {'note': 'this is a changed note'}

m: (old and new changed values)

<class 'dict'>: {'note OLD': 'this is a note', 'note NEW': 'this is a changed note'}

Kind regards

James

What Is an Audit Log? Audit Trails and How to Use Audit Logs, An audit log, also called an audit trail, is essentially a record of events and changes. IT devices across your network create logs based on� Audit logs - Provides traceability through logs for all changes done by various features within Azure AD. Examples of audit logs include changes made to any resources within Azure AD like adding or removing users, apps, groups, roles and policies. Security.

Somewhat whimsical solution:

d1 = {
    "date": "2019-04-25",
    "student_id": None,
    "booking_id": "",
    "key": "",
    "status": "ATTEND",
    "note": "this is a changed note",
    "charge": False,
    "greeting": "hello",  # this was added c.f. the original demo data
}
d2 = {
    "charge": False,
    "note": "this is a note",
    "key": "",
    "date": "2019-04-25",
    "student_id": None,
    "status": "ATTEND",
    "booking_id": "",
    "hello": "world",  # this was added c.f. the original demo data
}

class LabeledTuple(tuple):
    def __new__(cls, t, label):
        result = super().__new__(cls, t)
        result.label = label
        return result

    def __repr__(self):
        return self.label + super().__repr__()


def labeled_set(d, name):
    return {LabeledTuple(t, name) for t in d.items()}


print(sorted(labeled_set(d1, "OLD") ^ labeled_set(d2, "NEW")))
# [OLD('greeting', 'hello'), NEW('hello', 'world'), OLD('note', 'this is a changed note'), NEW('note', 'this is a note')]

Security Audit Logging Guideline, Resource Custodians must maintain, monitor, and analyze security audit logs for network connection changes or failures; changes to, or attempts to change,� Important. Changes to the administrator audit log configuration are always logged, regardless of whether the Set-AdministratorAuditLog cmdlet is included in the list of cmdlets being audited and whether audit logging is enabled or disabled.

Here's a solution based on yours. It assumes that both dictionaries have the same keys.

d1 = {
    "date": "2019-04-25",
    "student_id": None,
    "booking_id": "",
    "key": "",
    "status": "ATTEND",
    "note": "this is a changed note",
    "charge": False,
}
d2 = {
    "charge": False,
    "note": "this is a note",
    "key": "",
    "date": "2019-04-25",
    "student_id": None,
    "status": "ATTEND",
    "booking_id": "",
}

diffset = dict(set(d1.items()) ^ set(d2.items()))  # holds what has changed

m = {}
for key in diffset:
    m[key + " OLD"] = d1[key]
    m[key + " NEW"] = d2[key]

print(m)

The Purpose and Importance of Audit Trails, Audit logs capture events, showing “who” did “what” activity and o Changes to, or attempts to change, system security settings and controls. Enabled audit logs in O365 Security & Compliance waited 24 hrs and We made some changes in org-wide settings in teams admin center but Change organization setting teams activity audit logs not getting Showing no data. Please anyone guide me for this issue.

Using Audit Logs for Security and Compliance, An audit trail (also called audit log) is a security-relevant chronological record, set of records, Audit logs can likewise be valuable for performing forensic investigation, supporting the associations inside decisions relating to a research project, thus making clear the steps taken and changes made to the original protocol. Audit logging is disabled by default. After you enable audit logging, audit log messages are created for all login and logout actions, both successful and unsuccessful. Messages are also logged for administrative create, update, and delete actions taken from the Resilient user interface on users, roles, groups, and workspaces.

Audit trail, Audit logs are the centralized stream of all user activity within a team. exportable, available from an API, searchable and include well documented changes. The report “Logged Changes in Infotype Data” (RPUAUD00) can be very helpful in determining what changes were made and when to an infotype by allowing you to view the audit trail. In order for infotype changes to be logged, standard table configuration is required. Not only can SAP delivered infotypes be logged, but custom infotypes can also

Enterprise Ready SaaS App Guide to Audit Logging, Administrator auditing logging is enabled by default. All configuration changes made during the specified time period are displayed, and can� Perhaps you should include a comment on partial logging for some Infotypes (only specific fields), specially for fields that are never used in your Company. Also, if I am not mistaken, the changes made before the activation of the Audit Log will not show up in the Audit Reports.

Comments
  • This doesn't look like it'll handle added or removed keys correctly, though.