Class: RailsErrorDashboard::Plugins::AuditLogPlugin

Inherits:
RailsErrorDashboard::Plugin show all
Defined in:
lib/rails_error_dashboard/plugins/audit_log_plugin.rb

Overview

Example plugin: Audit logging Logs all error dashboard activities to a separate audit log

Usage:

RailsErrorDashboard.register_plugin(
  RailsErrorDashboard::Plugins::AuditLogPlugin.new(logger: Rails.logger)
)

Instance Method Summary collapse

Methods inherited from RailsErrorDashboard::Plugin

#enabled?, #on_register, #safe_execute

Constructor Details

#initialize(logger: Rails.logger) ⇒ AuditLogPlugin

Returns a new instance of AuditLogPlugin.



14
15
16
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 14

def initialize(logger: Rails.logger)
  @logger = logger
end

Instance Method Details

#descriptionObject



22
23
24
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 22

def description
  "Logs all error dashboard activities for compliance and auditing"
end

#nameObject



18
19
20
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 18

def name
  "Audit Logger"
end

#on_error_logged(error_log) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 30

def on_error_logged(error_log)
  log_event(
    event: "error_logged",
    error_id: error_log.id,
    error_type: error_log.error_type,
    platform: error_log.platform,
    timestamp: Time.current
  )
end

#on_error_recurred(error_log) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 40

def on_error_recurred(error_log)
  log_event(
    event: "error_recurred",
    error_id: error_log.id,
    error_type: error_log.error_type,
    occurrence_count: error_log.occurrence_count,
    timestamp: Time.current
  )
end

#on_error_resolved(error_log) ⇒ Object



50
51
52
53
54
55
56
57
58
59
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 50

def on_error_resolved(error_log)
  log_event(
    event: "error_resolved",
    error_id: error_log.id,
    error_type: error_log.error_type,
    resolved_by: error_log.resolved_by_name,
    resolution_comment: error_log.resolution_comment,
    timestamp: Time.current
  )
end

#on_error_viewed(error_log) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 79

def on_error_viewed(error_log)
  log_event(
    event: "error_viewed",
    error_id: error_log.id,
    error_type: error_log.error_type,
    timestamp: Time.current
  )
end

#on_errors_batch_deleted(error_ids) ⇒ Object



70
71
72
73
74
75
76
77
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 70

def on_errors_batch_deleted(error_ids)
  log_event(
    event: "errors_batch_deleted",
    count: error_ids.size,
    error_ids: error_ids,
    timestamp: Time.current
  )
end

#on_errors_batch_resolved(error_logs) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 61

def on_errors_batch_resolved(error_logs)
  log_event(
    event: "errors_batch_resolved",
    count: error_logs.size,
    error_ids: error_logs.map(&:id),
    timestamp: Time.current
  )
end

#versionObject



26
27
28
# File 'lib/rails_error_dashboard/plugins/audit_log_plugin.rb', line 26

def version
  "1.0.0"
end