Parent

Chef::Expander::Logger

Customized Logger class that dispenses with the unnecessary mutexing. As long as you write one line at a time, the OS will take care of keeping your output in order. Expander commonly runs as a cluster of worker processes so the mutexing wasn't actually helping us anyway.

We don't use the program name field in the logger, so support for that has been removed. The log format is also hardcoded since we don't ever change the format.

Attributes

log_device[R]

Public Class Methods

new(log_device) click to toggle source
# File lib/chef/expander/logger.rb, line 57
def initialize(log_device)
  @level = DEBUG
  init(log_device)
end

Public Instance Methods

<<(msg) click to toggle source
# File lib/chef/expander/logger.rb, line 72
def <<(msg)
  @log_device.print(msg)
end
add(severity=UNKNOWN, message = nil, progname = nil, &block) click to toggle source
# File lib/chef/expander/logger.rb, line 76
def add(severity=UNKNOWN, message = nil, progname = nil, &block)
  return true unless severity >= @level

  message ||= progname # level methods (e.g, #debug) pass explicit message as progname

  if message.nil? && block_given?
    message = yield
  end

  self << sprintf("[%s] %s: %s\n", Time.new.rfc2822(), LEVEL_TO_STR[severity], msg2str(message))
  true
end
Also aliased as: log
init(log_device) click to toggle source

(re-)initialize the Logger with a new IO object or file to log to.

# File lib/chef/expander/logger.rb, line 53
def init(log_device)
  @log_device = initialize_log_device(log_device)
end
level=(new_level) click to toggle source
# File lib/chef/expander/logger.rb, line 62
def level=(new_level)
  @level =  if new_level.kind_of?(Fixnum) && LEVEL_INTEGERS.key?(new_level)
    new
  elsif LEVELS.key?(new_level)
    LEVELS[new_level]
  else
    raise InvalidLogLevel, "#{new_level} is not a valid log level. Valid log levels are [#{LEVEL_INTEGERS.keys.join(',')}] and [#{LEVELS.join(',')}]"
  end
end
log(severity=UNKNOWN, message = nil, progname = nil, &block) click to toggle source
Alias for: add

[Validate]

Generated with the Darkfish Rdoc Generator 2.