Class: LogSinks::Logger
- Inherits:
-
Object
- Object
- LogSinks::Logger
- Defined in:
- lib/log_sinks/logger.rb,
lib/log_sinks/ruby_logger_adapter.rb
Overview
Logger is a object that captures log event and forward that to event sinks.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #as_ruby_logger(progname: nil) ⇒ Object
-
#initialize(name) ⇒ Logger
constructor
A new instance of Logger.
- #level=(level) ⇒ Object
- #level?(level) ⇒ Boolean
- #log_event(level, msg = nil, meta: nil, error: nil) ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/log_sinks/logger.rb', line 22 def name @name end |
Class Method Details
.[](name) ⇒ Object
15 16 17 18 19 |
# File 'lib/log_sinks/logger.rb', line 15 def [](name) ::LogSinks::Repository.instance.get_or_add(name) do |logger_name| Logger.new(logger_name) end end |
Instance Method Details
#as_ruby_logger(progname: nil) ⇒ Object
11 12 13 |
# File 'lib/log_sinks/ruby_logger_adapter.rb', line 11 def as_ruby_logger(progname: nil) RubyLoggerAdapter.new(self, progname) end |
#level=(level) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/log_sinks/logger.rb', line 35 def level=(level) @level = case level when String, Symbol then ::LogSinks::Level[level.to_sym] when ::LogSinks::Level then level end end |
#level?(level) ⇒ Boolean
31 32 33 |
# File 'lib/log_sinks/logger.rb', line 31 def level?(level) @level.val <= level.val end |
#log_event(level, msg = nil, meta: nil, error: nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/log_sinks/logger.rb', line 54 def log_event(level, msg = nil, meta: nil, error: nil) return false unless level?(level) msg = yield if msg.nil? && block_given? ||= {} [:error] = error unless error.nil? .merge!(MDC.items) if MDC.any? event = ::LogSinks::LogEvent.new(Time.now, level, @name, msg, meta: ) dispatch_event event end |