Class: Hanami::Logger::RackFormatter Private

Inherits:
Dry::Logger::Formatters::String
  • Object
show all
Defined in:
lib/hanami/logger/rack_formatter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Rack request log formatter for Dry Logger.

Formats rack request log entries with colorized output for HTTP verbs, status codes, and request paths, making it easier to visually scan logs in development.

HTTP verbs each have a distinct color. Status codes follow traffic-light coloring (2xx green, 3xx cyan, 4xx yellow, 5xx red), and the request path echoes the status color so both signals reinforce each other at a glance.

Colorization is only active when ‘colorize: true` is set in the logger options (the default in development).

Since:

  • 0.1.0

Constant Summary collapse

RACK_TEMPLATE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

<<~TEXT
  [%<progname>s] [%<severity>s] [%<time>s] \
  %<verb>s %<status>s %<elapsed>s %<ip>s %<path>s %<length>s %<payload>s
    %<params>s
TEXT
VERB_COLORS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

{
  "GET" => :green,
  "POST" => :yellow,
  "PUT" => :blue,
  "PATCH" => :blue,
  "DELETE" => :red,
  "HEAD" => :cyan
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ RackFormatter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RackFormatter.

Since:

  • 0.1.0



39
40
41
42
# File 'lib/hanami/logger/rack_formatter.rb', line 39

def initialize(**options)
  super
  @template = Dry::Logger::Formatters::Template[RACK_TEMPLATE]
end