logs Operation Logs¶
Author: Zhenyu Yang yangzhenyu@sust.edu.cn
Last updated: Apr 24, 2026
Corresponding API docs: Audit Log API
logs Code Entry¶
backend/apps/logs/models.pybackend/apps/logs/views/operation_log.pybackend/apps/logs/utils.pybackend/apps/logs/permissions.py
logs Core Data¶
OperationLog¶
Core dimensions logged:
useruser_roleactionmoduletarget_typetarget_iddescriptionrequest_ipuser_agentextracreated_at
Write Mechanism¶
OperationLogContextMiddlewarestores the current request in aContextVar.Business code can call
log_operation(...)directly.If the call site does not explicitly pass a
request, the logging utility attempts to retrieve it from the current context.
Key actions in borrowings, repairs, check-ins, and signage now have explicit operation logging.
Query & Export¶
OperationLogViewSetis a read-only endpoint.Supports filtering by time, user, role, module, and action.
exportexports the same filtered results as CSV.
Known Issues¶
The permission class
IsLogAdminstill checks the legacyuser.rolefield to identify super admins.However, the current user model uses
roles(JSON) and no longer has arolefield.As a result, the only reliably accessible log endpoints currently are for:
Django
is_superuserDjango
is_staff
To properly integrate the log endpoints into the new role system, this permission class needs to be fixed first.