Module: Logging

Included in:
Webhookd::App, Webhookd::Commandrunner, Webhookd::ParsePayload
Defined in:
lib/webhookd/logging.rb

Defined Under Namespace

Classes: MultiIO

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure_logger_for(classname) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/webhookd/logging.rb', line 32

def configure_logger_for(classname)
  logfile = File.open(Configuration.settings[:global][:logfile], 'a')
  logfile.sync = true
  logger = Logger.new MultiIO.new(STDOUT, logfile)
  case Configuration.settings[:global][:loglevel]
    when 'debug' then logger.level = Logger::DEBUG
    when 'info' then logger.level = Logger::INFO
    when 'warn' then logger.level = Logger::WARN
    when 'error' then logger.level = Logger::ERROR
    when 'fatal' then logger.level = Logger::FATAL
    when 'unknown' then logger.level = Logger::UNKNOWN
    else logger.level = Logger::DEBUG
  end
  logger.progname = classname
  logger
end

.logger_for(classname) ⇒ Object



28
29
30
# File 'lib/webhookd/logging.rb', line 28

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

Instance Method Details

#loggerObject

This is the magical bit that gets mixed into your classes



20
21
22
# File 'lib/webhookd/logging.rb', line 20

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