Class: Cloudenvoy::LoggerWrapper
- Inherits:
-
Object
- Object
- Cloudenvoy::LoggerWrapper
- Defined in:
- lib/cloudenvoy/logger_wrapper.rb
Overview
Add contextual information to logs generated by subscribers/publishers.
This class is a base class which aims at being inherited by object-specific logger wrappers. See Cloudenvoy::SubscriberLogger and Cloudenvoy::PublisherLogger.
Direct Known Subclasses
Class Attribute Summary collapse
-
.log_context_processor ⇒ Object
Returns the value of attribute log_context_processor.
Instance Attribute Summary collapse
-
#loggable ⇒ Object
Returns the value of attribute loggable.
Class Method Summary collapse
-
.default_context_processor ⇒ Proc
The default context processor.
Instance Method Summary collapse
-
#context_processor ⇒ Proc
Return the Proc responsible for formatting the log payload.
-
#debug(msg, &block) ⇒ Object
Log an debut message.
-
#error(msg, &block) ⇒ Object
Log an error message.
-
#fatal(msg, &block) ⇒ Object
Log an fatal message.
-
#formatted_message(msg) ⇒ String
Format main log message.
-
#info(msg, &block) ⇒ Object
Log an info message.
-
#initialize(loggable) ⇒ LoggerWrapper
constructor
Build a new instance of the class.
-
#log_block ⇒ Proc
The block to pass to log messages.
-
#logger ⇒ Logger, any
Return the Cloudenvoy logger.
-
#method_missing(name, *args, &block) ⇒ Any
Delegate all methods to the underlying logger.
-
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Check if the class respond to a certain method.
Constructor Details
#initialize(loggable) ⇒ LoggerWrapper
Build a new instance of the class.
32 33 34 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 32 def initialize(loggable) @loggable = loggable end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Any
Delegate all methods to the underlying logger.
125 126 127 128 129 130 131 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 125 def method_missing(name, *args, &block) if logger.respond_to?(name) logger.send(name, *args, &block) else super end end |
Class Attribute Details
.log_context_processor ⇒ Object
Returns the value of attribute log_context_processor.
14 15 16 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 14 def log_context_processor @log_context_processor end |
Instance Attribute Details
#loggable ⇒ Object
Returns the value of attribute loggable.
11 12 13 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 11 def loggable @loggable end |
Class Method Details
.default_context_processor ⇒ Proc
The default context processor. Aims at being overriden by child classes.
23 24 25 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 23 def self.default_context_processor @default_context_processor ||= ->(_) { {} } end |
Instance Method Details
#context_processor ⇒ Proc
Return the Proc responsible for formatting the log payload.
41 42 43 44 45 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 41 def context_processor @context_processor ||= loggable.class.[:log_context_processor] || self.class.log_context_processor || self.class.default_context_processor end |
#debug(msg, &block) ⇒ Object
Log an debut message.
112 113 114 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 112 def debug(msg, &block) (:debug, msg, &block) end |
#error(msg, &block) ⇒ Object
Log an error message.
92 93 94 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 92 def error(msg, &block) (:error, msg, &block) end |
#fatal(msg, &block) ⇒ Object
Log an fatal message.
102 103 104 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 102 def fatal(msg, &block) (:fatal, msg, &block) end |
#formatted_message(msg) ⇒ String
Format main log message.
72 73 74 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 72 def (msg) "[Cloudenvoy][#{loggable.class}] #{msg}" end |
#info(msg, &block) ⇒ Object
Log an info message.
82 83 84 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 82 def info(msg, &block) (:info, msg, &block) end |
#log_block ⇒ Proc
The block to pass to log messages.
52 53 54 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 52 def log_block @log_block ||= proc { context_processor.call(loggable) } end |
#logger ⇒ Logger, any
Return the Cloudenvoy logger.
61 62 63 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 61 def logger Cloudenvoy.logger end |
#respond_to_missing?(name, include_private = false) ⇒ Boolean
Check if the class respond to a certain method.
141 142 143 |
# File 'lib/cloudenvoy/logger_wrapper.rb', line 141 def respond_to_missing?(name, include_private = false) logger.respond_to?(name) || super end |