Class: IuguLogger::Railtie

Inherits:
Rails::Railtie
  • Object
show all
Defined in:
lib/iugu_logger/railtie.rb

Overview

Rails Railtie — wires the SDK into a Rails application with zero config for the common case:

* inserts IuguLogger::RequestLogger after ActionDispatch::DebugExceptions
  in the middleware stack
* registers IuguLogger::JobLogger::Sidekiq as a server-side middleware
  when Sidekiq is loaded
* derives a sensible default service_name from the app class
  (Rails.application.class.name → snake_case, dash-prefixed app name)

Rails.logger is intentionally NOT replaced in this release. Callers migrate to IuguLogger.event(…) for schema-conforming events; existing Rails.logger.X calls keep working unchanged. A future release may introduce an opt-in adapter to route Rails.logger through the buffer.

Spec: IUGU_LOGGING_STANDARD.md §6 (Railtie auto-config)

Class Method Summary collapse

Class Method Details

.derive_service_name(app) ⇒ Object

Best-effort service name from ‘MyApp::Application` → “my-app”. Falls back to “rails-app” when the app class is unusual.



83
84
85
86
87
88
89
90
91
92
# File 'lib/iugu_logger/railtie.rb', line 83

def derive_service_name(app)
  klass = app.class.name.to_s
  return 'rails-app' if klass.empty?

  first = klass.split('::').first
  first.gsub(/([A-Z]+)([A-Z][a-z])/, '\\1_\\2')
       .gsub(/([a-z\d])([A-Z])/, '\\1_\\2')
       .downcase
       .tr('_', '-')
end