Module: Smplkit::Logging::Levels Private

Defined in:
lib/smplkit/logging/levels.rb

Overview

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

Bidirectional mapping between Ruby stdlib Logger levels and smplkit canonical levels.

Stdlib Logger has DEBUG/INFO/WARN/ERROR/FATAL/UNKNOWN — no TRACE. The stdlib-logger adapter maps smplkit TRACE to stdlib DEBUG when applying levels, and maps stdlib DEBUG to smplkit DEBUG when discovering — there is no way to distinguish smplkit-TRACE-mapped-to- DEBUG from genuine DEBUG, which is consistent with how the Python stdlib-logging adapter handles the same gap.

Constant Summary collapse

STDLIB_TO_SMPL =

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

{
  ::Logger::DEBUG => LogLevel::DEBUG,
  ::Logger::INFO => LogLevel::INFO,
  ::Logger::WARN => LogLevel::WARN,
  ::Logger::ERROR => LogLevel::ERROR,
  ::Logger::FATAL => LogLevel::FATAL,
  ::Logger::UNKNOWN => LogLevel::SILENT
}.freeze
SMPL_TO_STDLIB =

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

{
  LogLevel::TRACE => ::Logger::DEBUG,
  LogLevel::DEBUG => ::Logger::DEBUG,
  LogLevel::INFO => ::Logger::INFO,
  LogLevel::WARN => ::Logger::WARN,
  LogLevel::ERROR => ::Logger::ERROR,
  LogLevel::FATAL => ::Logger::FATAL,
  LogLevel::SILENT => ::Logger::UNKNOWN
}.freeze
SEMANTIC_TO_SMPL =

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

SemanticLogger’s level system natively includes TRACE — a 1-to-1 map.

{
  trace: LogLevel::TRACE,
  debug: LogLevel::DEBUG,
  info: LogLevel::INFO,
  warn: LogLevel::WARN,
  error: LogLevel::ERROR,
  fatal: LogLevel::FATAL
}.freeze
SMPL_TO_SEMANTIC =

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

SEMANTIC_TO_SMPL.invert.freeze

Class Method Summary collapse

Class Method Details

.nearest_smpl_for(stdlib_level) ⇒ Object

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.



76
77
78
79
80
81
82
83
84
85
# File 'lib/smplkit/logging/levels.rb', line 76

def nearest_smpl_for(stdlib_level)
  sorted = STDLIB_TO_SMPL.keys.sort
  best = sorted.first
  sorted.each do |bp|
    break if bp > stdlib_level

    best = bp
  end
  STDLIB_TO_SMPL[best]
end

.semantic_level_to_smpl(level) ⇒ Object

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.



64
65
66
67
68
# File 'lib/smplkit/logging/levels.rb', line 64

def semantic_level_to_smpl(level)
  return LogLevel::INFO if level.nil?

  SEMANTIC_TO_SMPL[level.to_sym] || LogLevel::INFO
end

.smpl_level_to_semantic(level) ⇒ Object

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.



70
71
72
73
74
# File 'lib/smplkit/logging/levels.rb', line 70

def smpl_level_to_semantic(level)
  coerced = LogLevel.coerce(level)
  # SemanticLogger has no SILENT — closest equivalent is :fatal.
  SMPL_TO_SEMANTIC[coerced] || :fatal
end

.smpl_level_to_stdlib(level) ⇒ Object

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.



47
48
49
50
# File 'lib/smplkit/logging/levels.rb', line 47

def smpl_level_to_stdlib(level)
  coerced = LogLevel.coerce(level)
  SMPL_TO_STDLIB.fetch(coerced)
end

.stdlib_level_to_smpl(level) ⇒ Object

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.



41
42
43
44
45
# File 'lib/smplkit/logging/levels.rb', line 41

def stdlib_level_to_smpl(level)
  return LogLevel::DEBUG if level.nil?

  STDLIB_TO_SMPL[level] || nearest_smpl_for(level)
end