Module: TTY::Logger::Levels

Included in:
TTY::Logger
Defined in:
lib/tty/logger/levels.rb

Constant Summary collapse

DEBUG_LEVEL =
0
INFO_LEVEL =
1
WARN_LEVEL =
2
ERROR_LEVEL =
3
FATAL_LEVEL =
4
LEVEL_NAMES =
{
  debug: DEBUG_LEVEL,
  info: INFO_LEVEL,
  warn: WARN_LEVEL,
  error: ERROR_LEVEL,
  fatal: FATAL_LEVEL
}

Instance Method Summary collapse

Instance Method Details

#compare_levels(left, right) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Compares two levels by name or number


58
59
60
61
62
63
64
# File 'lib/tty/logger/levels.rb', line 58

def compare_levels(left, right)
  left = left.is_a?(Integer) ? left : level_to_number(left)
  right = right.is_a?(Integer) ? right : level_to_number(right)

  return :eq if left == right
  left < right ? :lt : :gt
end

#level_namesArray[Symbol]

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

All the default level names


25
26
27
# File 'lib/tty/logger/levels.rb', line 25

def level_names
  LEVEL_NAMES.keys
end

#level_to_number(level) ⇒ Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert level name to level number


36
37
38
39
# File 'lib/tty/logger/levels.rb', line 36

def level_to_number(level)
  LEVEL_NAMES[level.to_s.downcase.to_sym] ||
    raise(ArgumentError, "Invalid level #{level.inspect}")
end

#number_to_level(number) ⇒ Symbol

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert level number to level name


48
49
50
# File 'lib/tty/logger/levels.rb', line 48

def number_to_level(number)
  LEVEL_NAMES.key(number)
end