Class: Aruba::ArubaLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/platforms/aruba_logger.rb

Overview

Logger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ ArubaLogger

Create logger

Parameters:

  • opts (Hash) (defaults to: {})

    Options

Options Hash (opts):

  • :default_mode (Symbol)

    Log level


17
18
19
# File 'lib/aruba/platforms/aruba_logger.rb', line 17

def initialize(opts = {})
  @mode = opts.fetch(:default_mode, :info)
end

Instance Attribute Details

#modeObject

Returns the value of attribute mode


9
10
11
# File 'lib/aruba/platforms/aruba_logger.rb', line 9

def mode
  @mode
end

Instance Method Details

#debug(msg) ⇒ Object

Log a debug level log message


# File 'lib/aruba/platforms/aruba_logger.rb', line 27

#error(msg) ⇒ Object

Log an error level log message


# File 'lib/aruba/platforms/aruba_logger.rb', line 33

#fatal(msg) ⇒ Object

Log a fatal level log message


# File 'lib/aruba/platforms/aruba_logger.rb', line 21

#info(msg) ⇒ Object

Log an info level log message


# File 'lib/aruba/platforms/aruba_logger.rb', line 30

#loggerObject

Create new logger on every invocation to make capturing $stderr possible


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/aruba/platforms/aruba_logger.rb', line 47

def logger
  l = ::Logger.new($stderr)

  case mode
  when :debug
    l.level = ::Logger::DEBUG
    format_debug(l)
  when :silent
    l.level = 9_999
  when :info
    l.level = ::Logger::INFO
    format_standard(l)
  else
    l.level = ::Logger::INFO
    format_standard(l)
  end

  l
end

#mode?(m) ⇒ Boolean

Is mode?

Parameters:

  • m (String, Symbol)

    Mode to compare with

Returns:

  • (Boolean)

71
72
73
# File 'lib/aruba/platforms/aruba_logger.rb', line 71

def mode?(m)
  mode == m.to_sym
end

#unknown(msg) ⇒ Object

Log an unknown level log message


39
40
41
42
43
# File 'lib/aruba/platforms/aruba_logger.rb', line 39

[:fatal, :warn, :debug, :info, :error, :unknown].each do |m|
  define_method m do |msg|
    logger.public_send m, msg
  end
end

#warn(msg) ⇒ Object

Log a warn level log message


# File 'lib/aruba/platforms/aruba_logger.rb', line 24