module MrLogaLoga::Extensions::RailsExtension

Description

This patches Rails to allow it to work with loggers that accept keyword arguments.

Per default, Rails patches any logger during server startup to be able to broadcast any log messages to the console. This patch assumes that loggers only take args and blocks, so we have to change that.

During server startup Rails will always use the ActiveSupport::Logger to send data to the console. This was modified o changed to always use the user-configured logger.

Patches

Public Class Methods

apply() click to toggle source
# File lib/mr_loga_loga/extensions/rails.rb, line 22
def apply
  return unless defined?(Rails)

  patch_logger
  patch_server
end

Private Class Methods

broadcast_method() click to toggle source
# File lib/mr_loga_loga/extensions/rails.rb, line 57
def broadcast_method
  broadcast = ActiveSupport::Logger.method(:broadcast)
  broadcast && broadcast.arity == 1
rescue NameError
  false
end
patch_logger() click to toggle source
# File lib/mr_loga_loga/extensions/rails.rb, line 44
def patch_logger
  logger_defined = defined?(ActiveSupport::Logger)
  return unless logger_defined

  unless broadcast_method
    puts "WARNING: Failed to patch ActiveSupport::Logger. It looks like MrLogaLoga's patch in #{__FILE__} no "\
         "longer applies. Please contact MrLogaLoga's maintainers."
    return
  end

  ActiveSupport::Logger.include(LoggerPatch)
end
patch_server() click to toggle source
# File lib/mr_loga_loga/extensions/rails.rb, line 31
def patch_server
  server_defined = defined?(Rails::Server)
  return unless server_defined

  unless Rails::Server.private_method_defined?(:log_to_stdout)
    puts "WARNING: Failed to patch Rails::Server. It looks like MrLogaLoga's patch in #{__FILE__} no "\
         "longer applies. Please contact MrLogaLoga's maintainers."
    return
  end

  Rails::Server.prepend(ServerPatch)
end