Overview
The Audit Logging system provides comprehensive tracking of all user actions, system changes, and security events across the P.FLEX platform. Every significant operation is recorded with timestamps, user information, and detailed context for compliance and troubleshooting.Audit Log Data Model
TheAuditLog interface defines the structure of audit records:
Unique identifier for the audit log entry
Exact date and time of the action (automatically generated)
Name of the user who performed the action
Role of the user at the time of action (e.g., “Supervisor”, “Jefatura”)
System module where action occurred:
ADMIN- Administrative operationsACCESO- Authentication/login eventsOPERACIONES- Operational changesSISTEMA- System-level events
Brief description of the action performed (e.g., “Crear Usuario”, “Inicio de Sesión”)
Detailed description with context and affected entities
IP address of the user’s device (e.g., “192.168.1.45”)
Audit Service
TheAuditService manages all audit logging:
Audit logs use Angular signals for reactive UI updates. New entries appear in real-time without page refresh.
Logging Operations
Create audit entries using thelog() method:
Logs are prepended to the array so newest entries appear first. The module name is automatically converted to uppercase.
Tracked Events
User Management Events
All user administration actions are logged:Crear Usuario
Crear Usuario
ADMINDetails: Username and assigned roleExample: “Usuario creado: jperez (Supervisor)”Editar Usuario
Editar Usuario
ADMINDetails: Username of modified accountEliminar Usuario
Eliminar Usuario
ADMINDetails: Username or ID of deleted accountRole Management Events
Actualizar Rol
Actualizar Rol
ADMINDetails: Role nameTracks: Permission changes and role modificationsEliminar Rol
Eliminar Rol
ADMINDetails: Role name or IDMachine Management Events
Crear Máquina
Crear Máquina
ADMINDetails: Machine nameActualizar Máquina
Actualizar Máquina
ADMINDetails: Machine name and new statusEliminar Máquina
Eliminar Máquina
ADMINDetails: Machine nameSystem Configuration Events
ADMIN
Action: Configuración
Details: Generic message for system-wide configuration changes
Authentication Events
Inicio de Sesión
Inicio de Sesión
ACCESODetails: Username and shift informationExample: “Usuario jperez inició sesión en Turno Día.”Cierre de Sesión
Cierre de Sesión
ACCESODetails: Logout method (manual vs. automatic timeout)Operational Events
OPERACIONES
Action: Estado Máquina
Details: Machine name and status change
Use case: Track operational changes separate from administrative configuration
Audit Log Display
The audit component presents logs in a comprehensive table:Column Breakdown
Timestamp formatted as DD/MM/YYYY HH:mm:ssExample:
09/03/2026 14:32:15User’s full name with role displayed belowExample:
Categorized module with color coding:
- ADMIN - Blue badge
- ACCESO - Green badge
- OPERACIONES - Orange badge
- SISTEMA - Purple badge
Action title with detailed description belowExample:
Source IP address (simulated: 192.168.1.x)
Filtering and Search
While not shown in the current implementation, audit logs can be filtered by:- Date range
- User name
- Module type
- Action type
- IP address
The current implementation stores logs in memory. For production use, implement persistent storage and retention policies.
Compliance Features
Tamper-Proof
Audit logs cannot be modified or deleted by users (only append operations)
Complete Traceability
Every action includes user identity, timestamp, and detailed context
Real-Time Logging
Events are logged synchronously as they occur
Module Segregation
Actions are categorized by system module for easy filtering
Audit Log Modules
| Module | Purpose | Example Actions |
|---|---|---|
| ADMIN | Administrative operations | User creation, role updates, machine configuration |
| ACCESO | Authentication events | Login, logout, session timeout |
| OPERACIONES | Operational changes | Machine status changes, work order updates |
| SISTEMA | System-level events | Service startup, configuration changes |
Best Practices
Audit Logging Guidelines
Log Everything Significant: Track all actions that modify data or affect securityDescriptive Details: Include entity names, old/new values, and relevant contextConsistent Formatting: Use consistent action names across the applicationRegular Review: Monitor audit logs for suspicious activity or policy violationsRetention Policy: Define how long to retain logs based on compliance requirementsExport Capability: Allow exporting logs to CSV/PDF for external auditingAccess Control: Restrict audit log viewing to authorized personnel (Jefatura, Sistemas)
IP Address Tracking
The system simulates IP address tracking:Integration Points
Audit logging is integrated throughout the application:Future Enhancements
Alerting
Configure alerts for suspicious patterns (multiple failed logins, unauthorized access attempts)
Code Reference
Key source files:- Audit Service:
src/services/audit.service.ts:15-53 - Audit Interface:
src/services/audit.service.ts:4-13 - Audit Component:
src/features/audit/audit.component.ts:6-66 - Admin Integration:
src/features/admin/services/admin.service.ts:4,12 - Auth Integration:
src/services/state.service.ts:29,142,149
