Class: Gitlab::QA::TestLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/qa/test_logger.rb

Overview

Common test logger implementation

Constant Summary collapse

TIME_FORMAT =
"%Y-%m-%d %H:%M:%S"
LEVEL_COLORS =
{
  "DEBUG" => :magenta,
  "INFO" => :green,
  "WARN" => :yellow,
  "ERROR" => :red,
  "FATAL" => :indianred
}.freeze

Class Method Summary collapse

Class Method Details

.logger(level: :info, source: 'Gitlab QA', path: 'tmp') ⇒ ActiveSupport::Logger, ActiveSupport::BroadcastLogger

Combined logger instance

Parameters:

  • level (<Symbol, String>) (defaults to: :info)
  • source (String) (defaults to: 'Gitlab QA')

Returns:

  • (ActiveSupport::Logger, ActiveSupport::BroadcastLogger)


28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/gitlab/qa/test_logger.rb', line 28

def logger(level: :info, source: 'Gitlab QA', path: 'tmp')
  console_log = console_logger(level: level, source: source)
  file_log = file_logger(source: source, path: path)

  if ActiveSupport.const_defined?(:BroadcastLogger)
    ActiveSupport::BroadcastLogger.new(console_log, file_log)
  elsif ActiveSupport::Logger.respond_to?(:broadcast)
    console_log.extend(ActiveSupport::Logger.broadcast(file_log))
  else
    raise 'Could not configure logger broadcasting'
  end
end