Module: SemanticLogger::Levels
- Defined in:
- lib/semantic_logger/levels.rb
Constant Summary collapse
- LEVELS =
Logging levels in order of most detailed to most severe
%i[trace debug info warn error fatal].freeze
Class Method Summary collapse
-
.index(level) ⇒ Object
Internal method to return the log level as an internal index Also supports mapping the ::Logger levels to SemanticLogger levels.
-
.level(level_index) ⇒ Object
Returns the symbolic level for the supplied level index.
Class Method Details
.index(level) ⇒ Object
Internal method to return the log level as an internal index Also supports mapping the ::Logger levels to SemanticLogger levels
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/semantic_logger/levels.rb', line 8 def self.index(level) return if level.nil? index = if level.is_a?(Symbol) LEVELS.index(level) elsif level.is_a?(String) level = level.downcase.to_sym LEVELS.index(level) elsif level.is_a?(Integer) && defined?(::Logger::Severity) # Mapping of Rails and Ruby Logger levels to SemanticLogger levels @map_levels ||= begin levels = [] ::Logger::Severity.constants.each do |constant| levels[::Logger::Severity.const_get(constant)] = LEVELS.find_index(constant.downcase.to_sym) || LEVELS.find_index(:error) end levels end @map_levels[level] end raise "Invalid level:#{level.inspect} being requested. Must be one of #{LEVELS.inspect}" unless index index end |
.level(level_index) ⇒ Object
Returns the symbolic level for the supplied level index
34 35 36 |
# File 'lib/semantic_logger/levels.rb', line 34 def self.level(level_index) LEVELS[level_index] end |