Module: Sumologic::Interactive::FzfViewer::Formatter
- Defined in:
- lib/sumologic/interactive/fzf_viewer/formatter.rb
Class Method Summary collapse
- .colorize_level(level_str) ⇒ Object
- .format_level(level) ⇒ Object
- .format_time(timestamp_ms) ⇒ Object
- .pad(text, width) ⇒ Object
- .sanitize(text) ⇒ Object
- .truncate(text, length) ⇒ Object
Class Method Details
.colorize_level(level_str) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sumologic/interactive/fzf_viewer/formatter.rb', line 20 def colorize_level(level_str) case level_str.strip when 'ERROR', 'FATAL', 'CRITICAL' "#{Config::COLORS[:red]}#{level_str}#{Config::COLORS[:reset]}" when 'WARN', 'WARNING' "#{Config::COLORS[:yellow]}#{level_str}#{Config::COLORS[:reset]}" when 'INFO' "#{Config::COLORS[:cyan]}#{level_str}#{Config::COLORS[:reset]}" when 'DEBUG', 'TRACE' "#{Config::COLORS[:gray]}#{level_str}#{Config::COLORS[:reset]}" else level_str end end |
.format_level(level) ⇒ Object
15 16 17 18 |
# File 'lib/sumologic/interactive/fzf_viewer/formatter.rb', line 15 def format_level(level) level_str = level.to_s.upcase.ljust(Config::LEVEL_WIDTH) colorize_level(level_str) end |
.format_time(timestamp_ms) ⇒ Object
9 10 11 12 13 |
# File 'lib/sumologic/interactive/fzf_viewer/formatter.rb', line 9 def format_time() return 'N/A' unless Time.at(.to_i / 1000).strftime('%H:%M:%S') end |
.pad(text, width) ⇒ Object
44 45 46 |
# File 'lib/sumologic/interactive/fzf_viewer/formatter.rb', line 44 def pad(text, width) text.ljust(width) end |
.sanitize(text) ⇒ Object
35 36 37 |
# File 'lib/sumologic/interactive/fzf_viewer/formatter.rb', line 35 def sanitize(text) text.to_s.gsub(/[\n\r\t]/, ' ').squeeze(' ') end |
.truncate(text, length) ⇒ Object
39 40 41 42 |
# File 'lib/sumologic/interactive/fzf_viewer/formatter.rb', line 39 def truncate(text, length) text = text.to_s text.length > length ? "#{text[0...(length - 3)]}..." : text end |