Module: Lumberjack::TaggedLoggerSupport
- Defined in:
- lib/lumberjack/tagged_logger_support.rb
Overview
Methods to make Lumberjack::Logger API compatible with ActiveSupport::TaggedLogger.
Defined Under Namespace
Classes: Formatter
Instance Method Summary collapse
- #clear_tags! ⇒ Object
- #pop_tags(size = 1) ⇒ Object
- #push_tags(*tags) ⇒ Object
-
#tagged(*tags, &block) ⇒ Object
Compatibility with ActiveSupport::TaggedLogging which only supports adding tags as strings.
Instance Method Details
#clear_tags! ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/lumberjack/tagged_logger_support.rb', line 73 def if in_tag_context? tag("tagged" => nil) else tag_globally("tagged" => nil) end end |
#pop_tags(size = 1) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/lumberjack/tagged_logger_support.rb', line 60 def (size = 1) tagged_values = tag_value("tagged") return unless tagged_values.is_a?(Array) tagged_values = ((tagged_values.size > size) ? tagged_values[0, tagged_values.size - size] : nil) if in_tag_context? tag("tagged" => tagged_values) else tag_globally("tagged" => tagged_values) end end |
#push_tags(*tags) ⇒ Object
56 57 58 |
# File 'lib/lumberjack/tagged_logger_support.rb', line 56 def (*) tagged(*) end |
#tagged(*tags, &block) ⇒ Object
Compatibility with ActiveSupport::TaggedLogging which only supports adding tags as strings. Tags will be added to the “tagged” key in the logger’s tags hash as an array.
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/lumberjack/tagged_logger_support.rb', line 42 def tagged(*, &block) tagged_values = Array(tag_value("tagged")) = .flatten.collect(&:to_s).reject do |tag| tag.respond_to?(:blank?) ? tag.blank? : tag.empty? end tagged_values += unless .empty? if block || in_tag_context? tag("tagged" => tagged_values, &block) else tag_globally("tagged" => tagged_values) end end |