Class: Yast::Y2Logger

Inherits:
Logger
  • Object
show all
Includes:
Singleton
Defined in:
src/ruby/yast/y2logger.rb

Overview

A Ruby Logger which wraps Yast.y2*() calls

Constant Summary

CALL_FRAME =

location of the caller

2

Instance Method Summary collapse

Constructor Details

#initialize(*_args) ⇒ Y2Logger

Returns a new instance of Y2Logger



37
38
39
40
41
42
# File 'src/ruby/yast/y2logger.rb', line 37

def initialize(*_args)
  # do not write to any file, the actual logging is implemented in add()
  super(nil)
  # process also debug messages but might not be logged in the end
  self.level = ::Logger::DEBUG
end

Instance Method Details

#add(severity, _progname = nil, message = nil, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'src/ruby/yast/y2logger.rb', line 16

def add(severity, _progname = nil, message = nil, &block)
  message = block.call if block

  case severity
  when DEBUG
    Yast.y2debug(CALL_FRAME, message)
  when INFO
    Yast.y2milestone(CALL_FRAME, message)
  when WARN
    Yast.y2warning(CALL_FRAME, message)
  when ERROR
    Yast.y2error(CALL_FRAME, message)
  when FATAL
    Yast.y2error(CALL_FRAME, message)
  when UNKNOWN
    Yast.y2internal(CALL_FRAME, message)
  else
    Yast.y2internal(CALL_FRAME, "Unknown error level #{severity}: Error: #{message}")
  end
end