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
66
# File 'lib/aruba/platforms/aruba_logger.rb', line 47

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

  if mode == :debug
    format_debug(l)
  else
    format_standard(l)
  end

  l.level = case mode
            when :debug
              ::Logger::DEBUG
            when :silent
              9_999
            else
              ::Logger::INFO
            end

  l
end

#mode?(m) ⇒ Boolean

Is mode?

Parameters:

  • m (String, Symbol)

    Mode to compare with

Returns:

  • (Boolean)


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

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