Class: Hanami::Web::RackLogger Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/web/rack_logger.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 logger for Hanami apps

Since:

  • 2.0.0

Defined Under Namespace

Modules: Development Classes: UniversalLogger

Instance Method Summary collapse

Constructor Details

#initialize(logger, env: :development) ⇒ RackLogger

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 RackLogger.

Since:

  • 2.0.0



126
127
128
129
# File 'lib/hanami/web/rack_logger.rb', line 126

def initialize(logger, env: :development)
  @logger = UniversalLogger[logger]
  extend(Development) if %i[development test].include?(env)
end

Instance Method Details

#attach(rack_monitor) ⇒ Object

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.

Since:

  • 2.0.0



133
134
135
136
137
138
139
140
141
142
# File 'lib/hanami/web/rack_logger.rb', line 133

def attach(rack_monitor)
  rack_monitor.on :stop do |event|
    log_request event[:env], event[:status], event[:time]
  end

  rack_monitor.on :error do |event|
    # TODO: why we don't provide time on error?
    log_exception event[:env], event[:exception], 500, 0
  end
end

#log_exception(env, exception, status, elapsed) ⇒ Object

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.

Since:

  • 2.0.0



154
155
156
157
158
# File 'lib/hanami/web/rack_logger.rb', line 154

def log_exception(env, exception, status, elapsed)
  logger.tagged(:rack) do
    logger.error(exception, **data(env, status: status, elapsed: elapsed))
  end
end

#log_request(env, status, elapsed) ⇒ Object

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.

Since:

  • 2.0.0



146
147
148
149
150
# File 'lib/hanami/web/rack_logger.rb', line 146

def log_request(env, status, elapsed)
  logger.tagged(:rack) do
    logger.info(**data(env, status: status, elapsed: elapsed))
  end
end