Module: Collins::Api::Logging::Severity

Extended by:
Severity
Included in:
Severity
Defined in:
lib/collins/api/logging.rb

Overview

Constant Summary collapse

EMERGENCY =
"EMERGENCY"
ALERT =
"ALERT"
CRITICAL =
"CRITICAL"
ERROR =
"ERROR"
WARNING =
"WARNING"
NOTICE =
"NOTICE"
INFORMATIONAL =
"INFORMATIONAL"
DEBUG =
"DEBUG"
NOTE =
"NOTE"

Instance Method Summary collapse

Instance Method Details

#normalize(level) ⇒ Symbol

Convert a level into one appropriate for validating

Parameters:

  • level (Symbol, String)

    Severity level

Returns:

  • (Symbol)

    normalized (not neccesarily valid) severity level



38
39
40
# File 'lib/collins/api/logging.rb', line 38

def normalize level
  level.to_s.upcase.to_sym
end

#to_aArray<String>

Returns severity levels.

Returns:

  • (Array<String>)

    severity levels



51
52
53
54
# File 'lib/collins/api/logging.rb', line 51

def to_a
  s = Collins::Api::Logging::Severity
  s.constants.map{|c| s.const_get(c)}
end

#valid?(level) ⇒ Boolean

Check is a level is valid or not

Parameters:

  • level (Symbol, String)

    Severity level

Returns:

  • (Boolean)

    indicate whether valid or not



45
46
47
48
# File 'lib/collins/api/logging.rb', line 45

def valid? level
  level_s = normalize level
  Collins::Api::Logging::Severity.constants.include?(level_s)
end

#value_of(level) ⇒ String

Given a severity level, give back the severity, or nil if not valid

Parameters:

  • level (String, Symbol)

    Severity level

Returns:

  • (String)

    Severity level as string



26
27
28
29
30
31
32
33
# File 'lib/collins/api/logging.rb', line 26

def value_of level
  level_s = normalize level
  if valid? level_s then
    level_s.to_s
  else
    nil
  end
end