Class: Puppet::Util::Log::RateLimitedLogger

Inherits:
Object
  • Object
show all
Includes:
Puppet::Util::Logging
Defined in:
lib/puppet/util/log/rate_limited_logger.rb

Overview

Logging utility class that limits the frequency of identical log messages

Instance Method Summary collapse

Methods included from Puppet::Util::Logging

#clear_deprecation_warnings, #deprecation_warning, #format_exception, #get_deprecation_offender, #log_and_raise, #log_deprecations_to_file, #log_exception, #puppet_deprecation_warning

Constructor Details

#initialize(interval) ⇒ RateLimitedLogger

Returns a new instance of RateLimitedLogger.

Raises:

  • (ArgumentError)


7
8
9
10
11
# File 'lib/puppet/util/log/rate_limited_logger.rb', line 7

def initialize(interval)
  raise ArgumentError, "Logging rate-limit interval must be an integer" unless interval.is_a?(Integer)
  @interval = interval
  @log_record = {}
end

Instance Method Details

#send_log(level, message) ⇒ Object

Override the logging entry point to rate-limit it



14
15
16
# File 'lib/puppet/util/log/rate_limited_logger.rb', line 14

def send_log(level, message)
  Puppet::Util::Log.create({:level => level, :message => message}) if should_log?(level, message)
end