Class: BrainzLab::Utilities::LogFormatter
- Inherits:
-
Logger::Formatter
- Object
- Logger::Formatter
- BrainzLab::Utilities::LogFormatter
- Defined in:
- lib/brainzlab/utilities/log_formatter.rb
Overview
Beautiful log formatter for Rails development Provides colorized, structured output with request timing
Constant Summary collapse
- COLORS =
{ debug: "\e[36m", # Cyan info: "\e[32m", # Green warn: "\e[33m", # Yellow error: "\e[31m", # Red fatal: "\e[35m", # Magenta reset: "\e[0m", dim: "\e[2m", bold: "\e[1m", blue: "\e[34m", gray: "\e[90m" }.freeze
- SEVERITY_ICONS =
{ 'DEBUG' => 'đ', 'INFO' => 'âšī¸ ', 'WARN' => 'â ī¸ ', 'ERROR' => 'â', 'FATAL' => 'đ' }.freeze
- HTTP_METHODS =
{ 'GET' => "\e[32m", # Green 'POST' => "\e[33m", # Yellow 'PUT' => "\e[34m", # Blue 'PATCH' => "\e[34m", # Blue 'DELETE' => "\e[31m", # Red 'HEAD' => "\e[36m", # Cyan 'OPTIONS' => "\e[36m" # Cyan }.freeze
Class Method Summary collapse
-
.install! ⇒ Object
Install as Rails logger formatter.
Instance Method Summary collapse
- #call(severity, timestamp, progname, msg) ⇒ Object
-
#initialize(colorize: nil, show_timestamp: true, show_severity: true, compact: false) ⇒ LogFormatter
constructor
A new instance of LogFormatter.
Constructor Details
#initialize(colorize: nil, show_timestamp: true, show_severity: true, compact: false) ⇒ LogFormatter
Returns a new instance of LogFormatter.
47 48 49 50 51 52 53 |
# File 'lib/brainzlab/utilities/log_formatter.rb', line 47 def initialize(colorize: nil, show_timestamp: true, show_severity: true, compact: false) super() @colorize = colorize.nil? ? $stdout.tty? : colorize @show_timestamp = @show_severity = show_severity @compact = compact end |
Class Method Details
.install! ⇒ Object
Install as Rails logger formatter
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/brainzlab/utilities/log_formatter.rb', line 66 def self.install! return unless defined?(Rails) Rails.application.configure do config.log_formatter = BrainzLab::Utilities::LogFormatter.new( colorize: BrainzLab.configuration.log_formatter_colors, compact: BrainzLab.configuration.log_formatter_compact_assets ) end # Also hook into ActiveSupport::TaggedLogging if present return unless defined?(ActiveSupport::TaggedLogging) && Rails.logger.respond_to?(:formatter=) Rails.logger.formatter = new end |
Instance Method Details
#call(severity, timestamp, progname, msg) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/brainzlab/utilities/log_formatter.rb', line 55 def call(severity, , progname, msg) return '' if msg.nil? || msg.to_s.strip.empty? = (msg) return '' if () formatted = build_output(severity, , progname, ) "#{formatted}\n" end |