Class: SpreeCmCommissioner::AuditLogger
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::AuditLogger
- Defined in:
- app/services/spree_cm_commissioner/audit_logger.rb
Overview
AuditLogger is a safe write-through service for API audit events.
Usage:
AuditLogger.log!(
event_type: 'bookmebus.order.hold.request',
success: true,
metadata: { request: { method: 'POST', endpoint: '/api/v2/trip_reservations', body: {} } },
actor: integration,
auditable: order,
user: current_user,
correlation_id: 'uuid',
attempt: 0,
retention_days: 90
)
This service NEVER raises — any failure is swallowed and logged so it cannot disrupt the main application flow.
Class Method Summary collapse
-
.log!(event_type:, success: true, metadata: {}, auditable: nil, user: nil, correlation_id: nil, attempt: 0, retention_days: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists.
Class Method Details
.log!(event_type:, success: true, metadata: {}, auditable: nil, user: nil, correlation_id: nil, attempt: 0, retention_days: nil) ⇒ Object
rubocop:disable Metrics/ParameterLists
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/services/spree_cm_commissioner/audit_logger.rb', line 23 def log!( # rubocop:disable Metrics/ParameterLists event_type:, success: true, metadata: {}, auditable: nil, user: nil, correlation_id: nil, attempt: 0, retention_days: nil ) retention_until = (retention_days || 90).days.from_now.to_date SpreeCmCommissioner::AuditEventJob.perform_later( event_type: event_type, success: success, metadata: , auditable: auditable, user: user, correlation_id: correlation_id, attempt: attempt, retention_until: retention_until ) rescue StandardError => e CmAppLogger.error( label: 'AuditLogger failed to persist audit event', data: { event_type: event_type, error_class: e.class.name, error_message: e., backtrace: e.backtrace&.first(5) } ) nil end |