Class: RailsStdoutLogging::Rails2

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rails

heroku_stdout_logger, log_level

Class Method Details

.classesObject



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

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

.constantize(klass_name) ⇒ Object



40
41
42
43
44
# File 'lib/rails_stdout_logging/rails2.rb', line 40

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



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

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



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

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