Module: NewRelic::Agent::LogOnce

Included in:
AgentLogger, MemoryLogger
Defined in:
lib/new_relic/agent/log_once.rb

Constant Summary collapse

NUM_LOG_ONCE_KEYS =
1000

Instance Method Summary collapse

Instance Method Details

#clear_already_loggedObject



32
33
34
35
36
# File 'lib/new_relic/agent/log_once.rb', line 32

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

#log_once(level, key, *msgs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/new_relic/agent/log_once.rb', line 10

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