Module: QAT::Cucumber::Logger

Included in:
QAT::Cucumber
Defined in:
lib/qat/cucumber/logger.rb

Overview

Helper methods for logger configuration

Since:

  • 2.0.2

Instance Method Summary collapse

Instance Method Details

#config_logger(configuration) ⇒ Object

Configures Logger with a given configuration

Parameters:

  • configuration (Hash)

    logger configuration

Since:

  • 2.0.2



8
9
10
11
12
# File 'lib/qat/cucumber/logger.rb', line 8

def config_logger(configuration)
  config = validate_logger_config(configuration)

  load_logger_config(config) if config
end

#load_logger_config(to_load) ⇒ Object

Loads the logger configuration

Parameters:

  • to_load (Hash)

    logger configuration to load

Since:

  • 2.0.2



42
43
44
45
46
# File 'lib/qat/cucumber/logger.rb', line 42

def load_logger_config(to_load)
  Log4r::YamlConfigurator.load_yaml_file(to_load)

  log.info { "Loaded logger configuration from file '#{to_load}'" }
end

#validate_logger_config(configuration) ⇒ Object

Validates that a valid logger configuration exists in the QAT environment variable

Parameters:

  • configuration (Hash)

    logger configuration

Since:

  • 2.0.2



16
17
18
19
20
21
22
23
24
25
# File 'lib/qat/cucumber/logger.rb', line 16

def validate_logger_config(configuration)
  logger_env_config = ENV['QAT_LOGGER_CONFIG']

  if logger_env_config
    raise InvalidConfiguration.new "Configuration file for logger does not exist: '#{logger_env_config}'" unless File.exists?(logger_env_config.to_s)
    logger_env_config
  else
    validate_logger_yaml_config(configuration)
  end
end

#validate_logger_yaml_config(configuration) ⇒ Object

Validates that a valid logger configuration exists in a YAML file

Parameters:

  • configuration (Hash)

    logger configuration

Since:

  • 2.0.2



29
30
31
32
33
34
35
36
37
38
# File 'lib/qat/cucumber/logger.rb', line 29

def validate_logger_yaml_config(configuration)
  configuration_directory = configuration.directory

  files = [File.join(configuration_directory, configuration.environment, 'logger.yml'),
           File.join(configuration_directory, 'common', 'logger.yml')]

  config = files.select { |file| File.exist?(file) }

  config.first
end