# File lib/core/util/logger.rb, line 57 def self.add_logger(name, logger) logger.outputters = Log4r::StdoutOutputter.new('console') level = Logger.level.nil? ? 'off' : Logger.level set_level(level, logger) @@loggers[name] = logger end
# File lib/core/util/logger.rb, line 14 def self.level @@level end
# File lib/core/util/logger.rb, line 18 def self.level=level @@level = set_level(level) end
# File lib/core/util/logger.rb, line 24 def self.loggers @@loggers end
# File lib/core/util/logger.rb, line 77 def initialize(options = {}) if options.is_a?(String) options = { :logger => options } end config = Config.ensure(options) @resource = config.get(:resource, '') if config.get(:logger, false) self.logger = config[:logger] else self.logger = Log4r::Logger.new(@resource) end end
# File lib/core/util/logger.rb, line 39 def self.set_level(level, logger = nil) level_sym = level.to_s.downcase.to_sym level_id = level.to_s.upcase if logger.nil? loggers.each do |name, registered_logger| @@loggers[name].level = Log4r.const_get(level_id) end else if logger.levels.include?(level_id) logger.level = Log4r.const_get(level_id) end end level_sym end
# File lib/core/util/logger.rb, line 30 def self.set_levels(*levels) levels = levels.flatten.collect do |level| level.to_s.upcase end Log4r::Configurator.custom_levels(*levels) end
# File lib/core/util/logger.rb, line 118 def debug(message) @logger.debug(message) end
# File lib/core/util/logger.rb, line 136 def error(message) @logger.error(message) end
# File lib/core/util/logger.rb, line 142 def hook(message) @logger.hook(message) end
# File lib/core/util/logger.rb, line 124 def info(message) @logger.info(message) end
# File lib/core/util/logger.rb, line 94 def inspect "#<#{self.class}: #{@resource}>" end
# File lib/core/util/logger.rb, line 105 def logger=logger if logger.is_a?(String) @resource = logger @logger = Log4r::Logger.new(logger) else @logger = logger end self.class.add_logger(@resource, @logger) unless self.class.loggers.has_key?(@resource) end
# File lib/core/util/logger.rb, line 130 def warn(message) @logger.warn(message) end