Class: Quonfig::InternalLogger
- Inherits:
-
Object
- Object
- Quonfig::InternalLogger
- Defined in:
- lib/quonfig/internal_logger.rb
Overview
Internal logger for the Quonfig SDK Uses SemanticLogger if available, falls back to stdlib Logger
Class Attribute Summary collapse
-
.user_logger ⇒ Object
Returns the value of attribute user_logger.
Class Method Summary collapse
-
.using_quonfig_log_filter! ⇒ Object
Our client outputs debug logging, but if you aren’t using Quonfig logging this could be too chatty.
Instance Method Summary collapse
- #debug(message = nil, &block) ⇒ Object
- #error(message = nil, &block) ⇒ Object
- #fatal(message = nil, &block) ⇒ Object
- #info(message = nil, &block) ⇒ Object
-
#initialize(klass, logger: nil) ⇒ InternalLogger
constructor
A new instance of InternalLogger.
- #level ⇒ Object
- #level=(new_level) ⇒ Object
-
#trace(message = nil, &block) ⇒ Object
Log methods.
- #warn(message = nil, &block) ⇒ Object
Constructor Details
#initialize(klass, logger: nil) ⇒ InternalLogger
Returns a new instance of InternalLogger.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/quonfig/internal_logger.rb', line 16 def initialize(klass, logger: nil) @klass = klass @level_sym = nil # Track the symbol level for consistency @injected_logger = logger if @injected_logger @logger = @injected_logger @using_semantic = false elsif defined?(SemanticLogger) @logger = create_semantic_logger @using_semantic = true else @logger = create_stdlib_logger @using_semantic = false end # Track all instances regardless of logger type instances << self end |
Class Attribute Details
.user_logger ⇒ Object
Returns the value of attribute user_logger.
13 14 15 |
# File 'lib/quonfig/internal_logger.rb', line 13 def user_logger @user_logger end |
Class Method Details
.using_quonfig_log_filter! ⇒ Object
Our client outputs debug logging, but if you aren’t using Quonfig logging this could be too chatty. If you aren’t using the quonfig log filter, only log warn level and above
101 102 103 104 105 |
# File 'lib/quonfig/internal_logger.rb', line 101 def self.using_quonfig_log_filter! @@instances&.each do |logger| logger.level = :trace end end |
Instance Method Details
#debug(message = nil, &block) ⇒ Object
41 42 43 |
# File 'lib/quonfig/internal_logger.rb', line 41 def debug( = nil, &block) (:debug, , &block) end |
#error(message = nil, &block) ⇒ Object
53 54 55 |
# File 'lib/quonfig/internal_logger.rb', line 53 def error( = nil, &block) (:error, , &block) end |
#fatal(message = nil, &block) ⇒ Object
57 58 59 |
# File 'lib/quonfig/internal_logger.rb', line 57 def fatal( = nil, &block) (:fatal, , &block) end |
#info(message = nil, &block) ⇒ Object
45 46 47 |
# File 'lib/quonfig/internal_logger.rb', line 45 def info( = nil, &block) (:info, , &block) end |
#level ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/quonfig/internal_logger.rb', line 61 def level if @using_semantic @logger.level else # Return the symbol level we tracked, or map from Logger constant @level_sym || case @logger.level when Logger::DEBUG then :debug when Logger::INFO then :info when Logger::WARN then :warn when Logger::ERROR then :error when Logger::FATAL then :fatal else :warn end end end |
#level=(new_level) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/quonfig/internal_logger.rb', line 77 def level=(new_level) if @using_semantic @logger.level = new_level else # Track the symbol level for consistency @level_sym = new_level # Map symbol to Logger constant next_level = case new_level when :trace, :debug then Logger::DEBUG when :info then Logger::INFO when :warn then Logger::WARN when :error then Logger::ERROR when :fatal then Logger::FATAL else Logger::WARN end @logger.level = next_level if @logger.respond_to?(:level=) end end |
#trace(message = nil, &block) ⇒ Object
Log methods
37 38 39 |
# File 'lib/quonfig/internal_logger.rb', line 37 def trace( = nil, &block) (:trace, , &block) end |
#warn(message = nil, &block) ⇒ Object
49 50 51 |
# File 'lib/quonfig/internal_logger.rb', line 49 def warn( = nil, &block) (:warn, , &block) end |