Module: Timber::Integrations::Rails

Defined in:
lib/timber-rails.rb,
lib/timber-rails/version.rb,
lib/timber-rails/error_event.rb,
lib/timber-rails/rack_logger.rb,
lib/timber-rails/session_context.rb,
lib/timber-rails/active_support_log_subscriber.rb

Overview

Module for holding all Rails integrations. This module does not extend Integration because it’s dependent on Rack::HTTPEvents. This module simply disables the default HTTP request logging.

Defined Under Namespace

Modules: ActiveSupportLogSubscriber Classes: ErrorEvent, RackLogger, SessionContext

Constant Summary collapse

VERSION =
"1.0.1"

Class Method Summary collapse

Class Method Details

.enabled=(value) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/timber-rails.rb', line 44

def self.enabled=(value)
  Timber::Integrations::Rails::ErrorEvent.enabled = value
  Timber::Integrations::Rack::HTTPContext.enabled = value
  Timber::Integrations::Rack::HTTPEvents.enabled = value
  Timber::Integrations::Rack::UserContext.enabled = value
  SessionContext.enabled = value

  ActionController.enabled = value
  ActionView.enabled = value
  ActiveRecord.enabled = value
end

.enabled?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/timber-rails.rb', line 30

def self.enabled?
  Timber::Integrations::Rack::HTTPEvents.enabled?
end

.integrate!Object



34
35
36
37
38
39
40
41
42
# File 'lib/timber-rails.rb', line 34

def self.integrate!
  return false if !enabled?

  ActionController.integrate!
  ActionDispatch.integrate!
  ActionView.integrate!
  ActiveRecord.integrate!
  RackLogger.integrate!
end

.middlewaresObject

All enabled middlewares. The order is relevant. Middlewares that set context are added first so that context is included in subsequent log lines.



58
59
60
61
# File 'lib/timber-rails.rb', line 58

def self.middlewares
  @middlewares ||= [Timber::Integrations::Rack::HTTPContext, SessionContext, Timber::Integrations::Rack::UserContext,
    Timber::Integrations::Rack::HTTPEvents, Timber::Integrations::Rails::ErrorEvent].select(&:enabled?)
end