Sha256: 2be373846dc3951a695d38f851b2fb90720a02e10d217477fbe28d743a7d1b49
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
require 'logger' require 'webhookd/configuration' module Logging class MultiIO def initialize(*targets) @targets = targets end def write(*args) @targets.each {|t| t.write(*args)} end def close @targets.each(&:close) end end # This is the magical bit that gets mixed into your classes def logger @logger ||= Logging.logger_for(self.class.name) end # Use a hash class-ivar to cache a unique Logger per class: @loggers = {} class << self def logger_for(classname) @loggers[classname] ||= configure_logger_for(classname) end 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 end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
webhookd-0.0.9 | lib/webhookd/logging.rb |
webhookd-0.0.8 | lib/webhookd/logging.rb |
webhookd-0.0.7 | lib/webhookd/logging.rb |