Sha256: 82386597a7b15a803029a087461b51bd851a8d43bddbc0a4748def649e941a5d

Contents?: true

Size: 1.28 KB

Versions: 34

Compression:

Stored size: 1.28 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

module NewRelic
  module Agent
    module LogOnce
      NUM_LOG_ONCE_KEYS = 1000

      def log_once(level, key, *msgs)
        @already_logged_lock.synchronize do
          return if @already_logged.include?(key)

          if @already_logged.size >= NUM_LOG_ONCE_KEYS && key.kind_of?(String)
            # The reason for preventing too many keys in `logged` is for
            # memory concerns.
            # The reason for checking the type of the key is that we always want
            # to allow symbols to log, since there are very few of them.
            # The assumption here is that you would NEVER pass dynamically-created
            # symbols, because you would never create symbols dynamically in the
            # first place, as that would already be a memory leak in most Rubies,
            # even if we didn't hang on to them all here.
            return
          end

          @already_logged[key] = true
        end

        self.send(level, *msgs)
      end

      def clear_already_logged
        @already_logged_lock.synchronize do
          @already_logged = {}
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
newrelic_rpm-9.17.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.16.1 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.16.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.7.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.6.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.5.0 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.4.2 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.4.1 lib/new_relic/agent/log_once.rb
newrelic_rpm-9.4.0 lib/new_relic/agent/log_once.rb