Class: Pact::MockService::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/pact/mock_service/logger.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Logger

Returns a new instance of Logger.



9
10
11
12
13
14
15
16
# File 'lib/pact/mock_service/logger.rb', line 9

def initialize stream
  super stream
  @description = if stream.is_a? File
     File.absolute_path(stream).gsub(Dir.pwd + "/", '')
  else
    "standard out/err"
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



7
8
9
# File 'lib/pact/mock_service/logger.rb', line 7

def description
  @description
end

Class Method Details

.from_options(options) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/pact/mock_service/logger.rb', line 18

def self.from_options options
  log_stream = options[:log_file] || $stdout
  logger = new log_stream
  logger.formatter = options[:log_formatter] if options[:log_formatter]
  logger.level = logger_level(options[:log_level])
  logger
end

.logger_level(log_level_string) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pact/mock_service/logger.rb', line 26

def self.logger_level log_level_string
  if log_level_string
    begin
      Kernel.const_get('Logger').const_get(log_level_string.upcase)
    rescue NameError
      $stderr.puts "WARN: Ignoring log level '#{log_level_string}' as it is not a valid value. Valid values are: DEBUG INFO WARN ERROR FATAL. Using DEBUG."
      Logger::DEBUG
    end
  else
    Logger::DEBUG
  end
end