06/03 Optimize app
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
"""Thin wrapper for writing audit log entries."""
|
||||
import logging
|
||||
from flask import request
|
||||
|
||||
log = logging.getLogger('app.audit')
|
||||
|
||||
|
||||
def audit(action: str, description: str = ''):
|
||||
"""
|
||||
Write one audit log entry. Safe to call from any request context;
|
||||
silently swallows DB errors so it never breaks the main flow.
|
||||
"""
|
||||
try:
|
||||
from app.extensions import db
|
||||
from app.models.audit_log import AuditLog
|
||||
entry = AuditLog(
|
||||
action=action,
|
||||
description=description[:255] if description else '',
|
||||
ip_address=request.remote_addr,
|
||||
)
|
||||
db.session.add(entry)
|
||||
db.session.commit()
|
||||
log.info('[audit] %s — %s (ip=%s)', action, description, request.remote_addr)
|
||||
except Exception as exc:
|
||||
log.warning('[audit] failed to write entry: %s', exc)
|
||||
Reference in New Issue
Block a user