class MCollective::Logger::File_logger - mcollective version 2.12.5

# class MCollective::Logger::File_logger

Impliments a file based logger using the standard ruby logger class

To configure you should set:

    - config.logfile
    - config.keeplogs defaults to 2097152
    - config.max_log_size defaults to 5

### Public Instance Methods

log(level, from, msg) click to toggle source

       # File lib/mcollective/logger/file_logger.rb
    39 def log(level, from, msg)
    40   @logger.add(map_level(level)) { "#{from} #{msg}" }
    41 rescue
    42   # if this fails we probably cant show the user output at all,
    43   # STDERR it as last resort
    44   STDERR.puts("#{level}: #{msg}")
    45 end

reopen() click to toggle source

       # File lib/mcollective/logger/file_logger.rb
    47 def reopen
    48   level = @logger.level
    49   @logger.close
    50   start
    51   @logger.level = level
    52 end

set_logging_level(level) click to toggle source

       # File lib/mcollective/logger/file_logger.rb
    24 def set_logging_level(level)
    25   @logger.level = map_level(level)
    26 rescue Exception => e
    27   @logger.level = ::Logger::DEBUG
    28   log(:error, "", "Could not set logging to #{level} using debug instead: #{e.class} #{e}")
    29 end

start() click to toggle source

       # File lib/mcollective/logger/file_logger.rb
    13 def start
    14   config = Config.instance
    15
    16   @logger = ::Logger.new(config.logfile, config.keeplogs, config.max_log_size)
    17   @logger.formatter = ::Logger::Formatter.new
    18   # ISO-8601 with sub-second precision and offset from UTC.
    19   @logger.formatter.datetime_format = "%Y-%m-%dT%H:%M:%S.%6N%:z "
    20
    21   set_level(config.loglevel.to_sym)
    22 end

valid_levels() click to toggle source

       # File lib/mcollective/logger/file_logger.rb
    31 def valid_levels
    32   {:info  => ::Logger::INFO,
    33    :warn  => ::Logger::WARN,
    34    :debug => ::Logger::DEBUG,
    35    :fatal => ::Logger::FATAL,
    36    :error => ::Logger::ERROR}
    37 end