Commit 08d946e2 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'ml-qa-repo-logging' into 'master'

Re-enable debug logging of Git commands and output

See merge request gitlab-org/gitlab-ce!22608
parents bcbaccb9 a85c8e34
...@@ -113,21 +113,17 @@ module QA ...@@ -113,21 +113,17 @@ module QA
attr_reader :uri, :username, :password, :known_hosts_file, :private_key_file 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? def ssh_key_set?
!private_key_file.nil? !private_key_file.nil?
end end
def run(command_str) def run(command_str)
command = [env_vars, command_str, '2>&1'].compact.join(' ') 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, _ = Open3.capture2(command)
output = output.chomp.gsub(/\s+$/, '') output = output.chomp.gsub(/\s+$/, '')
warn "DEBUG: output=[#{output}]" if debug? Runtime::Logger.debug "Git: output=[#{output}]"
output output
end end
......
...@@ -10,11 +10,13 @@ module QA ...@@ -10,11 +10,13 @@ module QA
def_delegators :logger, :debug, :info, :warn, :error, :fatal, :unknown def_delegators :logger, :debug, :info, :warn, :error, :fatal, :unknown
singleton_class.module_eval do singleton_class.module_eval do
attr_writer :logger
def logger def logger
return @logger if @logger return @logger if @logger
@logger = ::Logger.new Runtime::Env.log_destination @logger = ::Logger.new Runtime::Env.log_destination
@logger.level = ::Logger::DEBUG @logger.level = Runtime::Env.debug? ? ::Logger::DEBUG : ::Logger::ERROR
@logger @logger
end end
end end
......
...@@ -3,9 +3,15 @@ ...@@ -3,9 +3,15 @@
require 'capybara/dsl' require 'capybara/dsl'
describe QA::Support::Page::Logging do describe QA::Support::Page::Logging do
include Support::StubENV
let(:page) { double().as_null_object } let(:page) { double().as_null_object }
before do 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(Capybara).to receive(:current_session).and_return(page)
allow(page).to receive(:current_url).and_return('http://current-url') allow(page).to receive(:current_url).and_return('http://current-url')
allow(page).to receive(:has_css?).with(any_args).and_return(true) allow(page).to receive(:has_css?).with(any_args).and_return(true)
......
# frozen_string_literal: true # frozen_string_literal: true
describe QA::Runtime::Logger do describe QA::Runtime::Logger do
before do
logger = Logger.new $stdout
logger.level = ::Logger::DEBUG
described_class.logger = logger
end
it 'logs debug' do it 'logs debug' do
expect { described_class.debug('test') }.to output(/DEBUG -- : test/).to_stdout_from_any_process expect { described_class.debug('test') }.to output(/DEBUG -- : test/).to_stdout_from_any_process
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment