Namespace

Class/Module Index [+]

Quicksearch

Mixlib::Log

Public Instance Methods

init(*opts) click to toggle source

Use Mixlib::Log.init when you want to set up the logger manually. Arguments to this method get passed directly to Logger.new, so check out the documentation for the standard Logger class to understand what to do here.

If this method is called with no arguments, it will log to STDOUT at the :info level.

It also configures the Logger instance it creates to use the custom Mixlib::Log::Formatter class.

# File lib/mixlib/log.rb, line 47
def init(*opts)
  @logger = (opts.empty? ? Logger.new(STDOUT) : Logger.new(*opts))
  @logger.formatter = Mixlib::Log::Formatter.new()
  @logger.level = Logger::WARN
  @logger
end
level(lv=nil) click to toggle source
# File lib/mixlib/log.rb, line 69
def level(lv=nil)
  if lv.nil?
    @@levels.find() {|l| logger.level==l[1]}[0]
  else
    self.level=(lv)
  end
end
level=(l) click to toggle source

Sets the level for the Logger object by symbol. Valid arguments are:

:debug
:info
:warn
:error
:fatal

Throws an ArgumentError if you feed it a bogus log level.

# File lib/mixlib/log.rb, line 63
def level=(l)
  lv = @@levels[l]
  raise ArgumentError, "Log level must be one of :debug, :info, :warn, :error, or :fatal" if lv.nil?
  logger.level = lv
end
logger() click to toggle source

init always returns a configured logger and creates a new one if it doesn't yet exist

# File lib/mixlib/log.rb, line 32
def logger
  @logger || init
end
logger=(value) click to toggle source
# File lib/mixlib/log.rb, line 36
def logger=(value)
  @logger=value
end
method_missing(method_symbol, *args, &block) click to toggle source

Passes any other method calls on directly to the underlying Logger object created with init. If this method gets hit before a call to Mixlib::Logger.init has been made, it will call Mixlib::Logger.init() with no arguments.

# File lib/mixlib/log.rb, line 80
def method_missing(method_symbol, *args, &block)
  logger.send(method_symbol, *args, &block)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.