Class: RailsStdoutJsonLogging::Rails2

Inherits:
Rails
  • Object
show all
Defined in:
lib/rails_stdout_json_logging/rails2.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rails

heroku_stdout_logger, log_level

Class Method Details

.classesObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/rails_stdout_json_logging/rails2.rb', line 28

def self.classes
  %w[
    ActiveSupport::Dependencies
    ActiveRecord::Base
    ActionController::Base
    ActionMailer::Base
    ActionView::Base
    ActiveResource::Base
  ]
end

.constantize(klass_name) ⇒ Object



39
40
41
42
43
# File 'lib/rails_stdout_json_logging/rails2.rb', line 39

def self.constantize(klass_name)
  klass_name.split('::').inject(Object) { |parent, child| parent.const_get(child) }
rescue NameError
  raise NameError, "Unable to find #{klass_name}"
end

.set_loggerObject



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rails_stdout_json_logging/rails2.rb', line 5

def self.set_logger
  super
  redefine_rails_logger!
  classes.each do |klass_name|
    begin
      klass = constantize(klass_name)
      klass.logger = ::Rails.logger
    rescue NameError => exception
      puts "WARNING: #{exception.message}"
    end
  end
end

Instance Method Details

#redefine_rails_logger!Object



18
19
20
21
22
23
24
25
26
# File 'lib/rails_stdout_json_logging/rails2.rb', line 18

def redefine_rails_logger!
  class << ::Rails
    def memoized_heroku_logger
      @logger ||= self.heroku_stdout_logger
    end
    alias_method :rails_default_logger, :logger
    alias_method :logger, :memoized_heroku_logger
  end
end