diff options
author | Mark Lapierre <mlapierre@gitlab.com> | 2018-10-25 11:49:33 -0400 |
---|---|---|
committer | Mark Lapierre <mlapierre@gitlab.com> | 2018-10-25 15:21:21 -0400 |
commit | a85c8e346f0844b0bc8079e03f942f4c53776efa (patch) | |
tree | f5a51384510376ebcf5ea37f1b451a1022b702a1 | |
parent | 4de9004175e7c1dfd0366c41d70573d4d686b292 (diff) | |
download | gitlab-ce-ml-qa-repo-logging.tar.gz |
Re-enable debug logging of Git commands and outputml-qa-repo-logging
-rw-r--r-- | qa/qa/git/repository.rb | 8 | ||||
-rw-r--r-- | qa/qa/runtime/logger.rb | 4 | ||||
-rw-r--r-- | qa/spec/page/logging_spec.rb | 6 | ||||
-rw-r--r-- | qa/spec/runtime/logger_spec.rb | 6 |
4 files changed, 17 insertions, 7 deletions
diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index c6a8891d398..27a88534258 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -113,21 +113,17 @@ module QA attr_reader :uri, :username, :password, :known_hosts_file, :private_key_file - def debug? - Runtime::Env.respond_to?(:verbose?) && Runtime::Env.verbose? - end - def ssh_key_set? !private_key_file.nil? end def run(command_str) command = [env_vars, command_str, '2>&1'].compact.join(' ') - warn "DEBUG: command=[#{command}]" if debug? + Runtime::Logger.debug "Git: command=[#{command}]" output, _ = Open3.capture2(command) output = output.chomp.gsub(/\s+$/, '') - warn "DEBUG: output=[#{output}]" if debug? + Runtime::Logger.debug "Git: output=[#{output}]" output end diff --git a/qa/qa/runtime/logger.rb b/qa/qa/runtime/logger.rb index 3baa24de0ec..7311615ea2d 100644 --- a/qa/qa/runtime/logger.rb +++ b/qa/qa/runtime/logger.rb @@ -10,11 +10,13 @@ module QA def_delegators :logger, :debug, :info, :error, :warn, :fatal, :unknown singleton_class.module_eval do + attr_writer :logger + def logger return @logger if @logger @logger = ::Logger.new Runtime::Env.log_destination - @logger.level = ::Logger::DEBUG + @logger.level = Runtime::Env.debug? ? ::Logger::DEBUG : ::Logger::ERROR @logger end end diff --git a/qa/spec/page/logging_spec.rb b/qa/spec/page/logging_spec.rb index 9f17de4edbf..9d56353062b 100644 --- a/qa/spec/page/logging_spec.rb +++ b/qa/spec/page/logging_spec.rb @@ -3,9 +3,15 @@ require 'capybara/dsl' describe QA::Support::Page::Logging do + include Support::StubENV + let(:page) { double().as_null_object } before do + logger = Logger.new $stdout + logger.level = ::Logger::DEBUG + QA::Runtime::Logger.logger = logger + allow(Capybara).to receive(:current_session).and_return(page) allow(page).to receive(:current_url).and_return('http://current-url') allow(page).to receive(:has_css?).with(any_args).and_return(true) diff --git a/qa/spec/runtime/logger_spec.rb b/qa/spec/runtime/logger_spec.rb index 794e1f9bfe6..44be3381bff 100644 --- a/qa/spec/runtime/logger_spec.rb +++ b/qa/spec/runtime/logger_spec.rb @@ -1,6 +1,12 @@ # frozen_string_literal: true describe QA::Runtime::Logger do + before do + logger = Logger.new $stdout + logger.level = ::Logger::DEBUG + described_class.logger = logger + end + it 'logs debug' do expect { described_class.debug('test') }.to output(/DEBUG -- : test/).to_stdout_from_any_process end |