Class: ExtendedLogger::Serializer
- Inherits:
-
Object
- Object
- ExtendedLogger::Serializer
- Defined in:
- lib/extended_logger/serializer.rb,
lib/extended_logger/serializer/text_formatter.rb
Defined Under Namespace
Classes: TextFormatter
Instance Attribute Summary collapse
- #color_scheme ⇒ Object
-
#log_format ⇒ Object
readonly
Returns the value of attribute log_format.
Class Method Summary collapse
Instance Method Summary collapse
- #call(message) ⇒ Object
- #format_text(message) ⇒ Object
-
#initialize(log_format) ⇒ Serializer
constructor
A new instance of Serializer.
Constructor Details
#initialize(log_format) ⇒ Serializer
Returns a new instance of Serializer.
6 7 8 |
# File 'lib/extended_logger/serializer.rb', line 6 def initialize log_format @log_format = log_format end |
Instance Attribute Details
#color_scheme ⇒ Object
30 31 32 |
# File 'lib/extended_logger/serializer.rb', line 30 def color_scheme @color_scheme ||= ColorScheme::None end |
#log_format ⇒ Object (readonly)
Returns the value of attribute log_format.
4 5 6 |
# File 'lib/extended_logger/serializer.rb', line 4 def log_format @log_format end |
Class Method Details
.build(log_format: nil, color_scheme: nil) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/extended_logger/serializer.rb', line 10 def self.build log_format: nil, color_scheme: nil log_format ||= Defaults.log_format instance = new log_format instance.color_scheme = color_scheme if color_scheme instance end |
Instance Method Details
#call(message) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/extended_logger/serializer.rb', line 18 def call = format_text .reduce String.new do |string, | color_scheme.colorize string << log_format.() string << "\n" string end end |
#format_text(message) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/extended_logger/serializer.rb', line 34 def format_text lines = TextFormatter.(.prose) lines.map do |line| = .dup .prose = line end end |