Class: Hiera::FallbackLogger Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hiera/fallback_logger.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Select from a given list of loggers the first one that it suitable and use that as the actual logger

Instance Method Summary collapse

Constructor Details

#initialize(*implementations) ⇒ FallbackLogger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Chooses the first suitable logger. For all of the loggers that are unsuitable it will issue a warning using the suitable logger stating that the unsuitable logger is not being used.

Parameters:

  • implementations (Array<Hiera::Logger>)

    the implementations to choose from



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hiera/fallback_logger.rb', line 12

def initialize(*implementations)
  warnings = []
  @implementation = implementations.find do |impl|
    if impl.respond_to?(:suitable?)
      if impl.suitable?
        true
      else
        warnings << "Not using #{impl.name}. It does not report itself to be suitable."
        false
      end
    else
      true
    end
  end

  if @implementation.nil?
    raise "No suitable logging implementation found."
  end

  warnings.each { |message| warn(message) }
end

Instance Method Details

#debug(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/hiera/fallback_logger.rb', line 38

def debug(message)
  @implementation.debug(message)
end

#warn(message) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
# File 'lib/hiera/fallback_logger.rb', line 34

def warn(message)
  @implementation.warn(message)
end