Class: Bifrossht::Logger

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bifrossht/logger.rb

Class Method Summary collapse

Class Method Details

.log_level(level = 'warn') ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bifrossht/logger.rb', line 11

def log_level(level = 'warn')
  mylevel = case level
            when 'debug' then ::Logger::DEBUG
            when 'info' then ::Logger::INFO
            when 'warn' then ::Logger::WARN
            when 'error' then ::Logger::ERROR
            when 'fatal' then ::Logger::FATAL
            else
              raise "Unknown log-level #{level}"
            end

  logger.level = mylevel
end

.loggerObject


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/bifrossht/logger.rb', line 25

def logger
  return @logger unless @logger.nil?

  @logger = ::Logger.new(STDERR)
  @logger.level = ::Logger::INFO
  @logger.formatter = proc do |severity, _datetime, _progname, msg|
    if severity == 'INFO'
      "#{msg}\n"
    else
      "#{severity}: #{msg}\n"
    end
  end

  @logger
end