Method: Puppet::Util::Logging#warn_once

Defined in:
lib/puppet/util/logging.rb

#warn_once(kind, key, message, file = nil, line = nil, level = :warning) ⇒ Object

Logs a (non deprecation) warning once for a given key.

Either :file and :line and/or :key must be passed.

Parameters:

  • kind (String)

    The kind of warning. The kind must be one of the defined kinds for the Puppet setting.

  • message (String)

    The message to log (logs via warning)

  • key (String)

    Key used to make this warning unique

  • file (String, :default, nil) (defaults to: nil)

    the File related to the warning

  • line (Integer, :default, nil) (defaults to: nil)

    the Line number related to the warning warning as unique

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

    log level to use, defaults to :warning



181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/puppet/util/logging.rb', line 181

def warn_once(kind, key, message, file = nil, line = nil, level = :warning)
  return if Puppet[:disable_warnings].include?(kind)

  $unique_warnings ||= {}
  if $unique_warnings.length < 100 then
    unless $unique_warnings.has_key?(key) then
      $unique_warnings[key] = message
      call_trace = if file == :default and line == :default
                     # Suppress the file and line number output
                     ''
                   else
                     error_location_str = Puppet::Util::Errors.error_location(file, line)
                     if error_location_str.empty?
                       "\n   " + _('(file & line not available)')
                     else
                       "\n   %{error_location}" % { error_location: error_location_str }
                     end
                   end
      send_log(level, "#{message}#{call_trace}")
    end
  end
end