Class: Cafeznik::CompactFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- Cafeznik::CompactFormatter
- Defined in:
- lib/cafeznik/log.rb
Constant Summary collapse
- COLOR_MAP =
{ colors: (30..37).to_a + (90..97).to_a # ANSI text colors }.freeze
- COLORS =
{ severity: { "DEBUG" => ["\e[44m", "\e[37m"], # Blue bg, white fg "INFO" => ["\e[42m", "\e[30m"], # Green bg, black fg "WARN" => ["\e[43m", "\e[30m"], # Yellow bg, black fg "ERROR" => ["\e[41m", "\e[37m"], # Red bg, white fg "FATAL" => ["\e[45m", "\e[30m"] # Magenta bg, black fg }, reset: "\e[0m" }.freeze
Instance Attribute Summary collapse
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #call(severity, _time, _progname, message) ⇒ Object
-
#initialize ⇒ CompactFormatter
constructor
A new instance of CompactFormatter.
Constructor Details
#initialize ⇒ CompactFormatter
Returns a new instance of CompactFormatter.
63 64 65 66 67 |
# File 'lib/cafeznik/log.rb', line 63 def initialize @component_colors = {} @verbose = false super end |
Instance Attribute Details
#verbose ⇒ Object
Returns the value of attribute verbose.
61 62 63 |
# File 'lib/cafeznik/log.rb', line 61 def verbose @verbose end |
Instance Method Details
#call(severity, _time, _progname, message) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cafeznik/log.rb', line 69 def call(severity, _time, _progname, ) component, method, content = () severity_bg, severity_fg = COLORS[:severity][severity] || COLORS[:severity]["DEBUG"] severity_prefix = "#{severity_bg}#{severity_fg}#{severity[0]}#{COLORS[:reset]}" source_prefix = format_source(component, method) formatted_content = content.gsub("\n", "\n" + (" " * (severity_prefix.size + source_prefix.size + 1))) if @verbose "#{severity_prefix} #{source_prefix} #{formatted_content}\n" else "#{formatted_content}\n" end end |