Class | Ohai::Log |
In: |
lib/ohai/log.rb
lib/ohai/log/formatter.rb |
Parent: | Object |
logger | [RW] |
Use Ohai::Logger.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 Ohai::Log::Formatter class.
# File lib/ohai/log.rb, line 38 38: def init(*opts) 39: if opts.length == 0 40: @logger = Logger.new(STDOUT) 41: else 42: @logger = Logger.new(*opts) 43: end 44: @logger.formatter = Ohai::Log::Formatter.new() 45: level(Ohai::Config.log_level) 46: end
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/ohai/log.rb, line 57 57: def level(loglevel) 58: init() unless @logger 59: case loglevel 60: when :debug 61: @logger.level = Logger::DEBUG 62: when :info 63: @logger.level = Logger::INFO 64: when :warn 65: @logger.level = Logger::WARN 66: when :error 67: @logger.level = Logger::ERROR 68: when :fatal 69: @logger.level = Logger::FATAL 70: else 71: raise ArgumentError, "Log level must be one of :debug, :info, :warn, :error, or :fatal" 72: end 73: end
Passes any other method calls on directly to the underlying Logger object created with init. If this method gets hit before a call to Ohai::Logger.init has been made, it will call Ohai::Logger.init() with no arguments.
# File lib/ohai/log.rb, line 78 78: def method_missing(method_symbol, *args) 79: init() unless @logger 80: if args.length > 0 81: @logger.send(method_symbol, *args) 82: else 83: @logger.send(method_symbol) 84: end 85: end