Sha256: f8625694dbc0687a5da4f8ffe856f5bc690b0b68a26dd13e5b7096cac41bc9d0

Contents?: true

Size: 1.55 KB

Versions: 22

Compression:

Stored size: 1.55 KB

Contents

module Honeybadger
  module Breadcrumbs
    # @api private
    #
    module LogWrapper
      def add(severity, message = nil, progname = nil)
        org_severity, org_message, org_progname = severity, message, progname
        message, progname = [progname, nil] if message.nil?
        message = message && message.to_s.strip
        unless should_ignore_log?(message, progname)
          Honeybadger.add_breadcrumb(message, category: :log, metadata: {
            severity: format_severity(severity),
            progname: progname
          })
        end

        super(org_severity, org_message, org_progname)
      end

      private

      def should_ignore_log?(message, progname)
        message.nil? ||
        message == "" ||
        Thread.current[:__hb_within_log_subscriber] ||
        progname == "honeybadger"
      end
    end

    # @api private
    #
    # This module is designed to be prepended into the
    # ActiveSupport::LogSubscriber for the sole purpose of silencing breadcrumb
    # log events. Since we already have specific breadcrumb events for each
    # class that provides LogSubscriber events, we want to filter out those
    # logs as they just become noise.
    module LogSubscriberInjector
      %w(info debug warn error fatal unknown).each do |level|
        define_method(level) do |*args, &block|
          begin
            Thread.current[:__hb_within_log_subscriber] = true
            super(*args, &block)
          ensure
            Thread.current[:__hb_within_log_subscriber] = false
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
honeybadger-5.0.2 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-5.0.1 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-5.0.0 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-5.0.0.beta1 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.12.2 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.12.1 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.12.0 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.11.0 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.10.0 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.9.0 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.8.0 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.7.3 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.7.2 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.7.1 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.7.0 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.6.0 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.5.6 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.5.5 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.5.4 lib/honeybadger/breadcrumbs/logging.rb
honeybadger-4.5.3 lib/honeybadger/breadcrumbs/logging.rb