Commit 85fe0381 authored by Andrejs Cunskis's avatar Andrejs Cunskis

Merge branch 'acunskis-use-common-logger' into 'master'

Reuse common logger implementation from gitlab-qa

See merge request gitlab-org/gitlab!82818
parents 2d3d675f a9eea185
...@@ -2,7 +2,7 @@ GEM ...@@ -2,7 +2,7 @@ GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
abstract_type (0.0.7) abstract_type (0.0.7)
activesupport (6.1.4.6) activesupport (6.1.4.7)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2) i18n (>= 1.6, < 2)
minitest (>= 5.1) minitest (>= 5.1)
...@@ -88,7 +88,7 @@ GEM ...@@ -88,7 +88,7 @@ GEM
faraday-net_http (1.0.1) faraday-net_http (1.0.1)
faraday-net_http_persistent (1.2.0) faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0) faraday-patron (1.0.0)
ffi (1.15.4) ffi (1.15.5)
ffi-compiler (1.0.1) ffi-compiler (1.0.1)
ffi (>= 1.0.0) ffi (>= 1.0.0)
rake rake
...@@ -121,11 +121,12 @@ GEM ...@@ -121,11 +121,12 @@ GEM
gitlab (4.18.0) gitlab (4.18.0)
httparty (~> 0.18) httparty (~> 0.18)
terminal-table (>= 1.5.1) terminal-table (>= 1.5.1)
gitlab-qa (7.17.1) gitlab-qa (7.24.4)
activesupport (~> 6.1) activesupport (~> 6.1)
gitlab (~> 4.18.0) gitlab (~> 4.18.0)
http (~> 5.0) http (~> 5.0)
nokogiri (~> 1.10) nokogiri (~> 1.10)
rainbow (~> 3.0.0)
table_print (= 1.5.7) table_print (= 1.5.7)
google-apis-compute_v1 (0.21.0) google-apis-compute_v1 (0.21.0)
google-apis-core (>= 0.4, < 2.a) google-apis-core (>= 0.4, < 2.a)
...@@ -172,7 +173,7 @@ GEM ...@@ -172,7 +173,7 @@ GEM
mime-types (~> 3.0) mime-types (~> 3.0)
multi_xml (>= 0.5.2) multi_xml (>= 0.5.2)
httpclient (2.8.3) httpclient (2.8.3)
i18n (1.8.11) i18n (1.10.0)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
ice_nine (0.11.2) ice_nine (0.11.2)
influxdb-client (1.17.0) influxdb-client (1.17.0)
...@@ -195,14 +196,14 @@ GEM ...@@ -195,14 +196,14 @@ GEM
mime-types-data (~> 3.2015) mime-types-data (~> 3.2015)
mime-types-data (3.2022.0105) mime-types-data (3.2022.0105)
mini_mime (1.1.0) mini_mime (1.1.0)
mini_portile2 (2.6.1) mini_portile2 (2.8.0)
minitest (5.15.0) minitest (5.15.0)
multi_json (1.15.0) multi_json (1.15.0)
multi_xml (0.6.0) multi_xml (0.6.0)
multipart-post (2.1.1) multipart-post (2.1.1)
netrc (0.11.0) netrc (0.11.0)
nokogiri (1.12.5) nokogiri (1.13.3)
mini_portile2 (~> 2.6.1) mini_portile2 (~> 2.8.0)
racc (~> 1.4) racc (~> 1.4)
octokit (4.21.0) octokit (4.21.0)
faraday (>= 0.9) faraday (>= 0.9)
...@@ -328,7 +329,7 @@ GEM ...@@ -328,7 +329,7 @@ GEM
uber (0.1.0) uber (0.1.0)
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.8) unf_ext (0.0.8.1)
unicode-display_width (2.1.0) unicode-display_width (2.1.0)
unparser (0.4.7) unparser (0.4.7)
abstract_type (~> 0.0.7) abstract_type (~> 0.0.7)
......
# frozen_string_literal: true # frozen_string_literal: true
require 'logger'
require 'forwardable' require 'forwardable'
module QA module QA
module Runtime module Runtime
module Logger class Logger
extend SingleForwardable extend SingleForwardable
LEVEL_COLORS = {
"DEBUG" => :magenta,
"INFO" => :green,
"WARN" => :yellow,
"ERROR" => :indianred,
"FATAL" => :red
}.freeze
def_delegators :logger, :debug, :info, :warn, :error, :fatal, :unknown def_delegators :logger, :debug, :info, :warn, :error, :fatal, :unknown
singleton_class.module_eval do def self.logger
attr_writer :logger @logger ||= Gitlab::QA::TestLogger.logger(
level: Runtime::Env.debug? ? ::Logger::DEBUG : ::Logger::INFO,
def logger source: 'QA Tests'
Rainbow.enabled = Runtime::Env.colorized_logs? )
@logger ||= ::Logger.new(Runtime::Env.log_destination).tap do |logger|
logger.level = Runtime::Env.debug? ? ::Logger::DEBUG : ::Logger::ERROR
logger.formatter = proc do |severity, datetime, progname, msg|
date_format = datetime.strftime("%Y-%m-%d %H:%M:%S")
msg_prefix = "[date=#{date_format} from=QA Tests] #{severity.ljust(5)} -- "
Rainbow(msg_prefix).send(LEVEL_COLORS.fetch(severity, :yellow)) + "#{msg}\n"
end
end
end
end end
end end
end end
......
...@@ -4,11 +4,10 @@ require 'capybara/dsl' ...@@ -4,11 +4,10 @@ require 'capybara/dsl'
RSpec.describe QA::Support::Page::Logging do RSpec.describe QA::Support::Page::Logging do
let(:page) { double.as_null_object } let(:page) { double.as_null_object }
let(:logger) { Gitlab::QA::TestLogger.logger(level: ::Logger::DEBUG, source: 'QA Tests') }
before do before do
logger = ::Logger.new $stdout allow(QA::Runtime::Logger).to receive(:logger).and_return(logger)
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(:find).and_return(page) allow(page).to receive(:find).and_return(page)
...@@ -59,7 +58,7 @@ RSpec.describe QA::Support::Page::Logging do ...@@ -59,7 +58,7 @@ RSpec.describe QA::Support::Page::Logging do
it 'logs find_element with class' do it 'logs find_element with class' do
expect { subject.find_element(:element, class: 'active') } expect { subject.find_element(:element, class: 'active') }
.to output(/finding :element with args {:class=>\"active\"}/).to_stdout_from_any_process .to output(/finding :element with args {:class=>"active"}/).to_stdout_from_any_process
end end
it 'logs click_element' do it 'logs click_element' do
...@@ -74,40 +73,40 @@ RSpec.describe QA::Support::Page::Logging do ...@@ -74,40 +73,40 @@ RSpec.describe QA::Support::Page::Logging do
it 'logs has_element?' do it 'logs has_element?' do
expect { subject.has_element?(:element) } expect { subject.has_element?(:element) }
.to output(/has_element\? :element \(wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned: true/).to_stdout_from_any_process .to output(/has_element\? :element \(wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned: true/o).to_stdout_from_any_process
end end
it 'logs has_element? with text' do it 'logs has_element? with text' do
expect { subject.has_element?(:element, text: "some text") } expect { subject.has_element?(:element, text: "some text") }
.to output(/has_element\? :element with text \"some text\" \(wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned: true/).to_stdout_from_any_process .to output(/has_element\? :element with text "some text" \(wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned: true/o).to_stdout_from_any_process
end end
it 'logs has_no_element?' do it 'logs has_no_element?' do
allow(page).to receive(:has_no_css?).and_return(true) allow(page).to receive(:has_no_css?).and_return(true)
expect { subject.has_no_element?(:element) } expect { subject.has_no_element?(:element) }
.to output(/has_no_element\? :element \(wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned: true/).to_stdout_from_any_process .to output(/has_no_element\? :element \(wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned: true/o).to_stdout_from_any_process
end end
it 'logs has_no_element? with text' do it 'logs has_no_element? with text' do
allow(page).to receive(:has_no_css?).and_return(true) allow(page).to receive(:has_no_css?).and_return(true)
expect { subject.has_no_element?(:element, text: "more text") } expect { subject.has_no_element?(:element, text: "more text") }
.to output(/has_no_element\? :element with text \"more text\" \(wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned: true/).to_stdout_from_any_process .to output(/has_no_element\? :element with text "more text" \(wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned: true/o).to_stdout_from_any_process
end end
it 'logs has_text?' do it 'logs has_text?' do
allow(page).to receive(:has_text?).and_return(true) allow(page).to receive(:has_text?).and_return(true)
expect { subject.has_text? 'foo' } expect { subject.has_text? 'foo' }
.to output(/has_text\?\('foo', wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned true/).to_stdout_from_any_process .to output(/has_text\?\('foo', wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned true/o).to_stdout_from_any_process
end end
it 'logs has_no_text?' do it 'logs has_no_text?' do
allow(page).to receive(:has_no_text?).with('foo', any_args).and_return(true) allow(page).to receive(:has_no_text?).with('foo', any_args).and_return(true)
expect { subject.has_no_text? 'foo' } expect { subject.has_no_text? 'foo' }
.to output(/has_no_text\?\('foo', wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned true/).to_stdout_from_any_process .to output(/has_no_text\?\('foo', wait: #{QA::Runtime::Browser::CAPYBARA_MAX_WAIT_TIME}\) returned true/o).to_stdout_from_any_process
end end
it 'logs finished_loading?' do it 'logs finished_loading?' do
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.describe QA::Runtime::Logger do RSpec.describe QA::Runtime::Logger do
before do it 'returns logger instance' do
logger = Logger.new $stdout expect(described_class.logger).to be_an_instance_of(::Logger)
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
it 'logs info' do
expect { described_class.info('test') }.to output(/INFO -- : test/).to_stdout_from_any_process
end
it 'logs warn' do
expect { described_class.warn('test') }.to output(/WARN -- : test/).to_stdout_from_any_process
end
it 'logs error' do
expect { described_class.error('test') }.to output(/ERROR -- : test/).to_stdout_from_any_process
end
it 'logs fatal' do
expect { described_class.fatal('test') }.to output(/FATAL -- : test/).to_stdout_from_any_process
end
it 'logs unknown' do
expect { described_class.unknown('test') }.to output(/ANY -- : test/).to_stdout_from_any_process
end end
end end
...@@ -3,12 +3,6 @@ ...@@ -3,12 +3,6 @@
require 'active_support/core_ext/integer/time' require 'active_support/core_ext/integer/time'
RSpec.describe QA::Support::Repeater do RSpec.describe QA::Support::Repeater do
before do
logger = ::Logger.new $stdout
logger.level = ::Logger::DEBUG
QA::Runtime::Logger.logger = logger
end
subject do subject do
Module.new do Module.new do
extend QA::Support::Repeater extend QA::Support::Repeater
......
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