Class: Hubbado::Log::Logger
- Inherits:
-
Object
- Object
- Hubbado::Log::Logger
- Defined in:
- lib/hubbado/log/logger.rb
Instance Attribute Summary collapse
-
#log_handlers ⇒ Object
Returns the value of attribute log_handlers.
-
#subject ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
-
#initialize(subject, log_handlers = [], level: nil) ⇒ Logger
constructor
A new instance of Logger.
-
#level ⇒ Object
A logger built without one follows the configuration, which is every logger the gem builds itself:
Log.configurenames no level, so a class using the Dependency module takes whatever the process was configured for. - #log(severity, msg, data = nil) ⇒ Object
Constructor Details
#initialize(subject, log_handlers = [], level: nil) ⇒ Logger
Returns a new instance of Logger.
7 8 9 10 11 |
# File 'lib/hubbado/log/logger.rb', line 7 def initialize(subject, log_handlers = [], level: nil) self.subject = subject self.log_handlers = Array(log_handlers) @level = level end |
Instance Attribute Details
#log_handlers ⇒ Object
Returns the value of attribute log_handlers.
4 5 6 |
# File 'lib/hubbado/log/logger.rb', line 4 def log_handlers @log_handlers end |
#subject ⇒ Object
Returns the value of attribute subject.
5 6 7 |
# File 'lib/hubbado/log/logger.rb', line 5 def subject @subject end |
Instance Method Details
#level ⇒ Object
A logger built without one follows the configuration, which is every logger the gem
builds itself: Log.configure names no level, so a class using the Dependency module
takes whatever the process was configured for.
16 |
# File 'lib/hubbado/log/logger.rb', line 16 def level = @level || Log.config.level |
#log(severity, msg, data = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/hubbado/log/logger.rb', line 18 def log(severity, msg, data = nil) unless SEVERITIES.keys.include? severity.to_sym raise ArgumentError, "Unknown serverity #{severity}" end # Read after the severity is checked, never before: the level decides what is printed, # not what may be said, so quietening a logger must not turn a typo into silence. return if SEVERITIES.fetch(severity.to_sym) < SEVERITIES.fetch(level) stacktrace = if data.is_a?(Exception) data. elsif STACKTRACE_SEVERITIES.include?(severity) format_stacktrace Kernel.caller end log_handlers.each do |handler| handler.log(subject, severity, msg, data, stacktrace) end end |