Class: Smplkit::LogLevel
- Inherits:
-
Object
- Object
- Smplkit::LogLevel
- Includes:
- Comparable
- Defined in:
- lib/smplkit/log_level.rb
Overview
Log severity levels used by the Smpl Logging service.
Acts as a string-valued enum: each constant equals its name when used in string contexts, and supports comparison via the ordinal. Members are declared in increasing severity order — matching the Ruby stdlib Logger convention (TRACE = least severe, SILENT = most severe).
Constant Summary collapse
- NAMES =
%w[TRACE DEBUG INFO WARN ERROR FATAL SILENT].freeze
- TRACE =
new("TRACE", 0)
- DEBUG =
new("DEBUG", 1)
- INFO =
new("INFO", 2)
- WARN =
new("WARN", 3)
- ERROR =
new("ERROR", 4)
- FATAL =
new("FATAL", 5)
- SILENT =
new("SILENT", 6)
- ALL =
[TRACE, DEBUG, INFO, WARN, ERROR, FATAL, SILENT].freeze
- BY_NAME =
ALL.to_h { |lvl| [lvl.name, lvl] }.freeze
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Canonical level name (e.g. “INFO”).
-
#ordinal ⇒ Integer
readonly
Severity ordinal — TRACE=0 (lowest) through SILENT=6 (highest).
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(name, ordinal) ⇒ LogLevel
constructor
A new instance of LogLevel.
- #inspect ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(name, ordinal) ⇒ LogLevel
Returns a new instance of LogLevel.
19 20 21 22 23 |
# File 'lib/smplkit/log_level.rb', line 19 def initialize(name, ordinal) @name = name.freeze @ordinal = ordinal freeze end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns Canonical level name (e.g. “INFO”).
14 15 16 |
# File 'lib/smplkit/log_level.rb', line 14 def name @name end |
#ordinal ⇒ Integer (readonly)
Returns Severity ordinal — TRACE=0 (lowest) through SILENT=6 (highest).
17 18 19 |
# File 'lib/smplkit/log_level.rb', line 17 def ordinal @ordinal end |
Class Method Details
.coerce(value) ⇒ Object
57 58 59 60 61 |
# File 'lib/smplkit/log_level.rb', line 57 def self.coerce(value) return value if value.is_a?(LogLevel) from_string(value) end |
.from_string(value) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/smplkit/log_level.rb', line 47 def self.from_string(value) raise ArgumentError, "log level cannot be nil" if value.nil? key = value.to_s.upcase level = BY_NAME[key] raise ArgumentError, "unknown log level: #{value.inspect}" unless level level end |
Instance Method Details
#<=>(other) ⇒ Object
31 |
# File 'lib/smplkit/log_level.rb', line 31 def <=>(other) = other.is_a?(LogLevel) ? @ordinal <=> other.ordinal : nil |
#==(other) ⇒ Object
28 |
# File 'lib/smplkit/log_level.rb', line 28 def ==(other) = other.is_a?(LogLevel) ? @ordinal == other.ordinal : @name == other |
#eql?(other) ⇒ Boolean
30 |
# File 'lib/smplkit/log_level.rb', line 30 def eql?(other) = self == other |
#hash ⇒ Object
29 |
# File 'lib/smplkit/log_level.rb', line 29 def hash = @ordinal.hash |
#inspect ⇒ Object
27 |
# File 'lib/smplkit/log_level.rb', line 27 def inspect = "#<Smplkit::LogLevel #{@name}>" |
#to_s ⇒ Object
25 |
# File 'lib/smplkit/log_level.rb', line 25 def to_s = @name |
#to_str ⇒ Object
26 |
# File 'lib/smplkit/log_level.rb', line 26 def to_str = @name |