Module: Logging

Included in:
IcingaCertService::Client
Defined in:
lib/logging.rb

Overview


Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configure_logger_for(classname) ⇒ Object

configure the logger



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/logging.rb', line 27

def configure_logger_for( classname )

  log_level = ENV.fetch('LOG_LEVEL', 'DEBUG' )

  level = log_level.upcase.dup

  # DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN
  log_level = case level
    when 'DEBUG'
      Logger::DEBUG   # Low-level information for developers.
    when 'INFO'
      Logger::INFO    # Generic (useful) information about system operation.
    when 'WARN'
      Logger::WARN    # A warning.
    when 'ERROR'
      Logger::ERROR   # A handleable error condition.
    when 'FATAL'
      Logger::FATAL   # An unhandleable error that results in a program crash.
    else
      Logger::UNKNOWN # An unknown message that should always be logged.
    end

  $stdout.sync           = true
  logger                 = Logger.new($stdout)
  logger.level           = log_level
  logger.datetime_format = '%Y-%m-%d %H:%M:%S'
  logger.formatter       = proc do |severity, datetime, progname, msg|
    "[#{datetime.strftime( logger.datetime_format )}] #{severity.ljust(5)}  #{msg}\n"
  end

  logger
end

.logger_for(classname) ⇒ Object

create an logger instance for classname



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

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

Instance Method Details

#loggerObject

global function to use the logger instance



10
11
12
# File 'lib/logging.rb', line 10

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