Module: NagiosHerald::Logging

Instance Method Summary collapse

Instance Method Details

#configure_logger_for(classname) ⇒ Object

instantiates a Logger instance default to STDOUT



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/nagios-herald/logging.rb', line 27

def configure_logger_for(classname)
  logfile = Config.config['logfile'] ? Config.config['logfile'] : STDOUT
  if logfile.eql?("STDOUT")
    logfile = STDOUT
  end
  begin
    logger = Logger.new(logfile)
  rescue Exception => e
    puts "Failed to open #{logfile} for writing: #{e.message}"
    puts "Defaulting to STDOUT"
    logger = Logger.new(STDOUT)
  end
  logger.datetime_format = "%Y-%m-%d %H:%M:%S"
  logger.progname = "#{File.basename $0} (#{classname})"
  logger.formatter = proc { |severity, datetime, progname, msg|
    "[#{datetime}] #{severity} -- #{progname}: #{msg}\n"
  }
  logger
end

#loggerObject



9
10
11
# File 'lib/nagios-herald/logging.rb', line 9

def logger
@logger ||= Logging.logger_for(self.class.name)
end

#logger_for(classname) ⇒ Object

effectively sets the progname



21
22
23
# File 'lib/nagios-herald/logging.rb', line 21

def logger_for(classname)
  @loggers[classname] ||= configure_logger_for(classname)
end