Class: StandardId::Events::Subscribers::LoggingSubscriber

Inherits:
Base
  • Object
show all
Defined in:
lib/standard_id/events/subscribers/logging_subscriber.rb

Constant Summary collapse

LOG_LEVELS =
{
  "authentication.attempt.started" => :debug,
  "authentication.attempt.succeeded" => :info,
  "authentication.attempt.failed" => :warn,
  "authentication.password.validated" => :debug,
  "authentication.password.failed" => :warn,
  "authentication.otp.validated" => :debug,
  "authentication.otp.failed" => :warn,
  "session.creating" => :debug,
  "session.created" => :info,
  "session.validating" => :debug,
  "session.validated" => :debug,
  "session.expired" => :info,
  "session.revoked" => :info,
  "session.refreshed" => :debug,
  "account.creating" => :debug,
  "account.created" => :info,
  "account.verified" => :info,
  "account.status_changed" => :warn,
  "account.activated" => :info,
  "account.deactivated" => :warn,
  "account.locked" => :warn,
  "account.unlocked" => :info,
  "identifier.created" => :debug,
  "identifier.verification.started" => :debug,
  "identifier.verification.succeeded" => :info,
  "identifier.verification.failed" => :warn,
  "identifier.linked" => :info,
  "oauth.authorization.requested" => :debug,
  "oauth.authorization.granted" => :info,
  "oauth.authorization.denied" => :info,
  "oauth.token.issuing" => :debug,
  "oauth.token.issued" => :info,
  "oauth.token.refreshed" => :debug,
  "oauth.code.consumed" => :debug,
  "passwordless.code.requested" => :debug,
  "passwordless.code.generated" => :debug,
  "passwordless.code.sent" => :info,
  "passwordless.code.verified" => :info,
  "passwordless.code.failed" => :warn,
  "passwordless.account.created" => :info,
  "social.auth.started" => :debug,
  "social.auth.callback_received" => :debug,
  "social.user_info.fetched" => :debug,
  "social.account.created" => :info,
  "social.account.linked" => :info,
  "social.auth.completed" => :info,
  "credential.password.created" => :info,
  "credential.password.reset_initiated" => :info,
  "credential.password.reset_completed" => :info,
  "credential.password.changed" => :info,
  "credential.client_secret.created" => :info,
  "credential.client_secret.rotated" => :warn
}.freeze
DEFAULT_LOG_LEVEL =
:debug

Instance Method Summary collapse

Methods inherited from Base

attach, attached?, detach, #handle, subscribe_to, subscribe_to_pattern, subscribed_events, subscription_pattern

Instance Method Details

#call(event) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/standard_id/events/subscribers/logging_subscriber.rb', line 64

def call(event)
  return unless logging_enabled?

  log_level = LOG_LEVELS.fetch(event.short_name, DEFAULT_LOG_LEVEL)
  payload = build_payload(event, log_level)

  case log_level
  when :debug then StandardId.logger.debug(payload)
  when :info  then StandardId.logger.info(payload)
  when :warn  then StandardId.logger.warn(payload)
  when :error then StandardId.logger.error(payload)
  end
end

#handle_error(error, event) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/standard_id/events/subscribers/logging_subscriber.rb', line 78

def handle_error(error, event)
  StandardId.logger.error({
    subject: "standard_id.logging_subscriber.error",
    event_type: event.short_name,
    error: error.message
  })
end