Class: Findbug::Capture::MessageHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/findbug/capture/message_handler.rb

Overview

MessageHandler captures non-exception events (messages).

WHY CAPTURE MESSAGES?

Not every important event is an exception. Sometimes you want to track:

  • Security events: “User exceeded rate limit”

  • Business events: “Payment failed validation”

  • Warnings: “External API response slow”

  • Debug info: “Cache miss for critical key”

These aren’t exceptions, but you want to see them in your error dashboard alongside actual errors.

USAGE

Findbug.capture_message("User exceeded rate limit", :warning, user_id: 123)
Findbug.capture_message("Payment validation failed", :error, order_id: 456)
Findbug.capture_message("Scheduled task completed", :info, duration: 45.2)

Class Method Summary collapse

Class Method Details

.capture(message, level = :info, extra_context = {}) ⇒ Object

Capture a message

Parameters:

  • message (String)

    the message to capture

  • level (Symbol) (defaults to: :info)

    severity level (:info, :warning, :error)

  • extra_context (Hash) (defaults to: {})

    additional context



38
39
40
41
42
43
44
45
# File 'lib/findbug/capture/message_handler.rb', line 38

def capture(message, level = :info, extra_context = {})
  return unless Findbug.enabled?

  event_data = build_event_data(message, level, extra_context)
  Storage::RedisBuffer.push_error(event_data)
rescue StandardError => e
  Findbug.logger.error("[Findbug] MessageHandler failed: #{e.message}")
end