Class: TextFormatter
- Inherits:
-
Object
- Object
- TextFormatter
- Defined in:
- lib/formatters/text_formatter.rb
Constant Summary collapse
- MAX_CHAR =
130- MAX_CHAR_FLOAT =
There’s some problems with float decimal precision. Keep this 5 below MAX_CHAR
125.00- COLORS =
{ info: "96", warning: "33", debug: "34", error: "91", fatal: "31" }
Instance Attribute Summary collapse
-
#short_date ⇒ Object
Returns the value of attribute short_date.
-
#with_color ⇒ Object
Returns the value of attribute with_color.
Instance Method Summary collapse
-
#format_msg(hash, level) ⇒ Object
Split the message into 145 char chunks.
-
#initialize ⇒ TextFormatter
constructor
A new instance of TextFormatter.
Constructor Details
#initialize ⇒ TextFormatter
Returns a new instance of TextFormatter.
16 17 18 19 20 |
# File 'lib/formatters/text_formatter.rb', line 16 def initialize if block_given? yield(self) end end |
Instance Attribute Details
#short_date ⇒ Object
Returns the value of attribute short_date.
14 15 16 |
# File 'lib/formatters/text_formatter.rb', line 14 def short_date @short_date end |
#with_color ⇒ Object
Returns the value of attribute with_color.
14 15 16 |
# File 'lib/formatters/text_formatter.rb', line 14 def with_color @with_color end |
Instance Method Details
#format_msg(hash, level) ⇒ Object
Split the message into 145 char chunks. Prepend level. Append DateTime
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/formatters/text_formatter.rb', line 24 def format_msg(hash, level) @level = level # Log level str = "" # Final String we return. We keep appending to this count = 0 # Use to indent on 2nd+ iteration str_keys_values = add_key_values_to_str(hash) s_msg = split_msg(str_keys_values) # Split message incase it's MAX_CHAR+ chars s_msg.each do |n| str += count == 0 ? "#{add_log_level(str)}#{get_date} | " : "#{add_log_level(str)}" str += count == 0 ? "#{n}\n" : " " * (get_date.length) + " | #{n}\n" # Indent if 2nd+ iteration count += 1 end str end |