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



138
139
140
141
# File 'lib/hanami/web/rack_logger.rb', line 138

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



145
146
147
148
149
150
151
152
153
154
# File 'lib/hanami/web/rack_logger.rb', line 145

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



169
170
171
172
173
174
175
# File 'lib/hanami/web/rack_logger.rb', line 169

def log_exception(env, exception, status, elapsed)
  logger.tagged(:rack) do
    logger.error(exception) do
      data(env, status: status, elapsed: elapsed)
    end
  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



158
159
160
161
162
163
164
165
# File 'lib/hanami/web/rack_logger.rb', line 158

def log_request(env, status, elapsed)
  logger.tagged(:rack) do

    logger.info do
      data(env, status: status, elapsed: elapsed)
    end
  end
end