Class: Dry::Logger::Formatters::Template
- Inherits:
-
Object
- Object
- Dry::Logger::Formatters::Template
- Defined in:
- lib/dry/logger/formatters/template.rb
Overview
Basic string formatter.
This formatter returns log entries in key=value format.
Direct Known Subclasses
Defined Under Namespace
Classes: Colorized
Constant Summary collapse
- TOKEN_REGEXP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/%<(\w*)>s/
- MESSAGE_TOKEN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"%<message>s"
Instance Attribute Summary collapse
- #tokens ⇒ Object readonly private
- #value ⇒ Object readonly private
Class Method Summary collapse
- .[](value) ⇒ Object private
Instance Method Summary collapse
- #%(tokens) ⇒ Object private
- #colorize(color, input) ⇒ Object private
- #include?(token) ⇒ Boolean private
-
#initialize(value) ⇒ Template
constructor
private
A new instance of Template.
Constructor Details
#initialize(value) ⇒ Template
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Template.
65 66 67 68 |
# File 'lib/dry/logger/formatters/template.rb', line 65 def initialize(value) @value = value @tokens = value.scan(TOKEN_REGEXP).flatten(1).map(&:to_sym).to_set end |
Instance Attribute Details
#tokens ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 |
# File 'lib/dry/logger/formatters/template.rb', line 31 def tokens @tokens end |
#value ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
27 28 29 |
# File 'lib/dry/logger/formatters/template.rb', line 27 def value @value end |
Class Method Details
.[](value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 |
# File 'lib/dry/logger/formatters/template.rb', line 35 def self.[](value) cache.fetch(value) { cache[value] = (colorized?(value) ? Template::Colorized : Template).new(value) } end |
Instance Method Details
#%(tokens) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 75 76 |
# File 'lib/dry/logger/formatters/template.rb', line 72 def %(tokens) output = value % tokens output.strip! output.split(NEW_LINE).map(&:rstrip).join(NEW_LINE) end |
#colorize(color, input) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
80 81 82 |
# File 'lib/dry/logger/formatters/template.rb', line 80 def colorize(color, input) "\e[#{Colors[color.to_sym]}m#{input}\e[0m" end |
#include?(token) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'lib/dry/logger/formatters/template.rb', line 86 def include?(token) tokens.include?(token) end |