Module: Logging

Defined in:
lib/monkey_patches/Logger.rb

Overview

Original Code for this module can be found here

http://stackoverflow.com/questions/917566/ruby-share-logger-instance-among-module-classes

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure_logger_for(classname) ⇒ Object



19
20
21
22
23
# File 'lib/monkey_patches/Logger.rb', line 19

def configure_logger_for(classname)
  logger = Logger.new(STDOUT)
  logger.progname = classname
  logger
end

.logger_for(classname) ⇒ Object



15
16
17
# File 'lib/monkey_patches/Logger.rb', line 15

def logger_for(classname)
  @loggers[classname] ||= configure_logger_for(classname)
end

Instance Method Details

#debugging_enabled?Boolean

Returns:

  • (Boolean)


36
37
38
39
40
41
42
# File 'lib/monkey_patches/Logger.rb', line 36

def debugging_enabled?
  if logger.level == Logger::DEBUG
    return true
  else
    return false
  end
end

#loggerObject



7
8
9
# File 'lib/monkey_patches/Logger.rb', line 7

def logger
  @logger ||= Logging.logger_for(self.class.name)
end

#turn_off_debuggingObject

Turn off debugging. Will now only display errors and fatal messages.



27
28
29
# File 'lib/monkey_patches/Logger.rb', line 27

def turn_off_debugging
  logger.level = Logger::ERROR
end

#turn_on_debuggingObject

Turn on debugging



32
33
34
# File 'lib/monkey_patches/Logger.rb', line 32

def turn_on_debugging
  logger.level = Logger::DEBUG
end