Module: LogStruct::Integrations::Puma::ErrorLoggerPatch

Extended by:
T::Sig
Defined in:
lib/log_struct/integrations/puma.rb

Overview

Puma::ErrorLogger writes request errors (an exception the app didn't handle, a malformed request, an SSL error) as plain text to STDERR, with the request's query string. Log them as structured lines, with the method and path but not the query string, which LogStruct can't filter there.

Instance Method Summary collapse

Instance Method Details

#info(options = {}) ⇒ T.untyped

Parameters:

  • options (Hash{Symbol => T.untyped}) (defaults to: {})

Returns:

  • (T.untyped)


416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
# File 'lib/log_struct/integrations/puma.rb', line 416

def info(options = {})
  error = options[:error]
  return super unless error.is_a?(Exception)

  env = options[:req]&.env
  ::LogStruct.error(::LogStruct::Log::Puma::Error.new(
    error_class: error.class,
    message: error.message,
    backtrace: error.backtrace,
    error_context: options[:text]&.to_s,
    http_method: env&.dig("REQUEST_METHOD"),
    path: env && (env["REQUEST_PATH"] || env["PATH_INFO"])
  ))
  nil
rescue => e
  ::LogStruct::Integrations::Puma.handle_integration_error(e)
  super
end