Class: Warren::LogTagger
- Inherits:
-
Object
- Object
- Warren::LogTagger
- Defined in:
- lib/warren/log_tagger.rb
Overview
Applies a tag to any messages sent to the logger.
Class Method Summary collapse
-
.level(name) ⇒ Void
Define ‘name` methods which forward on to the similarly named method on logger, with the tag applied.
Instance Method Summary collapse
-
#debug(message) ⇒ Object
Forwards message on to logger with #tag prefix See Logger::debug.
-
#error(message) ⇒ Object
Forwards message on to logger with #tag prefix See Logger::error.
-
#info(message) ⇒ Object
Forwards message on to logger with #tag prefix See Logger::info.
-
#initialize(logger:, tag:) ⇒ LogTagger
constructor
Create a new log tagger, which applies a tag to all messages before forwarding them on to the logger.
-
#warn(message) ⇒ Object
Forwards message on to logger with #tag prefix See Logger::warn.
Constructor Details
#initialize(logger:, tag:) ⇒ LogTagger
Create a new log tagger, which applies a tag to all messages before forwarding them on to the logger
13 14 15 16 |
# File 'lib/warren/log_tagger.rb', line 13 def initialize(logger:, tag:) @logger = logger @tag = tag end |
Class Method Details
.level(name) ⇒ Void
Define ‘name` methods which forward on to the similarly named method on logger, with the tag applied
25 26 27 28 29 30 31 32 33 |
# File 'lib/warren/log_tagger.rb', line 25 def self.level(name) define_method(name) do |arg = nil, &block| if block @logger.public_send(name, arg) { tag(block.call) } else @logger.public_send(name, tag(arg)) end end end |
Instance Method Details
#debug(message) ⇒ Object
Forwards message on to logger with #tag prefix See Logger::debug
38 |
# File 'lib/warren/log_tagger.rb', line 38 level :debug |
#error(message) ⇒ Object
Forwards message on to logger with #tag prefix See Logger::error
50 |
# File 'lib/warren/log_tagger.rb', line 50 level :error |
#info(message) ⇒ Object
Forwards message on to logger with #tag prefix See Logger::info
42 |
# File 'lib/warren/log_tagger.rb', line 42 level :info |
#warn(message) ⇒ Object
Forwards message on to logger with #tag prefix See Logger::warn
46 |
# File 'lib/warren/log_tagger.rb', line 46 level :warn |