Module: Loggable::ClassMethods

Included in:
Class, Module
Defined in:
lib/loggable/log_methods.rb

Instance Method Summary collapse

Instance Method Details

#loggerObject

If ::Rails.logger is defined, that will be returned. If no logger has been defined, a new STDOUT Logger will be created.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/loggable/log_methods.rb', line 18

def logger
  
  if defined?(::Rails) && ::Rails.respond_to?(:version)
    if ::Rails.version >= "2.1" && !::Rails.logger.nil?
      @@logger = ::Rails.logger
    end
  end
  
  # If none of the above was able to set @@logger, create a new default logger
  @@logger ||= ::Logger.new(STDOUT)
  
  return @@logger
end

#logger=(logger) ⇒ Object

Use this method on any of your classes to trigger the logging facility:

MyClass.logger = Logger.new('/path/to/logfile')

Now you can call the 'logger' method inside a class or instance method to log at the specified level. See the README for details.



12
13
14
# File 'lib/loggable/log_methods.rb', line 12

def logger=(logger)
  @@logger = logger
end