Class: ScoutApm::Logging::Loggers::Swaps::Rails

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/logging/loggers/swaps/rails.rb

Overview

Swaps in our logger for the Rails logger.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Rails

Returns a new instance of Rails.



15
16
17
# File 'lib/scout_apm/logging/loggers/swaps/rails.rb', line 15

def initialize(context)
  @context = context
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/scout_apm/logging/loggers/swaps/rails.rb', line 9

def context
  @context
end

Class Method Details

.present?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/scout_apm/logging/loggers/swaps/rails.rb', line 11

def self.present?
  defined?(::Rails) && ::Rails.logger
end

Instance Method Details

#update_logger!Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/scout_apm/logging/loggers/swaps/rails.rb', line 19

def update_logger!
  # In Rails 7.1, broadcast logger was added which allows sinking to multiple IO devices.
  if defined?(::ActiveSupport::BroadcastLogger) && log_instance.is_a?(::ActiveSupport::BroadcastLogger)
    context.logger.debug('Rails Broadcast logger detected. Adding new logger to broadcast.')
    add_logger_to_broadcast!
  else
    context.logger.debug("Swapping in Proxy for current Rails logger: #{log_instance.class}.")
    swap_in_proxy_logger!
  end

  new_log_location
end