class Nucleon::Util::Logger

Attributes

resource[R]

Public Class Methods

add_logger(name, logger) click to toggle source
# 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
level() click to toggle source
# File lib/core/util/logger.rb, line 14
def self.level
  @@level  
end
level=(level) click to toggle source
# File lib/core/util/logger.rb, line 18
def self.level=level
  @@level = set_level(level)
end
loggers() click to toggle source
# File lib/core/util/logger.rb, line 24
def self.loggers
  @@loggers
end
new(options = {}) click to toggle source
# 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
set_level(level, logger = nil) click to toggle source
# 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
set_levels(*levels) click to toggle source
# 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

Public Instance Methods

debug(message) click to toggle source
# File lib/core/util/logger.rb, line 118
def debug(message)
  @logger.debug(message)
end
error(message) click to toggle source
# File lib/core/util/logger.rb, line 136
def error(message)
  @logger.error(message)
end
hook(message) click to toggle source
# File lib/core/util/logger.rb, line 142
def hook(message)
  @logger.hook(message)  
end
info(message) click to toggle source
# File lib/core/util/logger.rb, line 124
def info(message)
  @logger.info(message)
end
inspect() click to toggle source
# File lib/core/util/logger.rb, line 94
def inspect
  "#<#{self.class}: #{@resource}>"
end
logger=(logger) click to toggle source
# 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
warn(message) click to toggle source
# File lib/core/util/logger.rb, line 130
def warn(message)
  @logger.warn(message)
end