Class: RailsAi::Security::AuditLogger
- Inherits:
-
Object
- Object
- RailsAi::Security::AuditLogger
- Defined in:
- lib/rails_ai/security/audit_logger.rb
Class Method Summary collapse
- .log_api_call(endpoint, user_id, success: true) ⇒ Object
- .log_rate_limit_exceeded(identifier, limit) ⇒ Object
- .log_security_event(event_type, details = {}) ⇒ Object
- .log_validation_error(error_type, details) ⇒ Object
Class Method Details
.log_api_call(endpoint, user_id, success: true) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/rails_ai/security/audit_logger.rb', line 20 def self.log_api_call(endpoint, user_id, success: true) log_security_event(:api_call, { endpoint: endpoint, user_id: user_id, success: success, timestamp: Time.now }) end |
.log_rate_limit_exceeded(identifier, limit) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/rails_ai/security/audit_logger.rb', line 37 def self.log_rate_limit_exceeded(identifier, limit) log_security_event(:rate_limit_exceeded, { identifier: identifier, limit: limit, timestamp: Time.now }) end |
.log_security_event(event_type, details = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/rails_ai/security/audit_logger.rb', line 6 def self.log_security_event(event_type, details = {}) return unless defined?(Rails) && Rails.logger log_entry = { timestamp: Time.now.iso8601, event_type: event_type, details: details, user_id: RailsAi::Context.user_id, request_id: RailsAi::Context.request_id } Rails.logger.info("[SECURITY] #{log_entry.to_json}") end |
.log_validation_error(error_type, details) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/rails_ai/security/audit_logger.rb', line 29 def self.log_validation_error(error_type, details) log_security_event(:validation_error, { error_type: error_type, details: details, timestamp: Time.now }) end |