Commit 5c5749fd authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch '13413-geo-allow-the-log-cursor-to-log-to-stdout' into 'master'

Geo: Allow Geo log cursor to log output to stdout

Closes #13413

See merge request gitlab-org/gitlab-ee!15077
parents a6ce154e 3b87cde4
......@@ -41,12 +41,6 @@ class GeoLogCursorOptionParser
end
end
module StdoutLogger
def full_log_path
STDOUT
end
end
if $0 == __FILE__
options = GeoLogCursorOptionParser.parse(ARGV)
......@@ -57,7 +51,7 @@ if $0 == __FILE__
# Monkey patch the logging class because multiple places use it (that
# contain mostly class methods) and is not possible to pass
# options[:stdout_logging] around without a refactor.
Gitlab::Geo::Logger.extend(StdoutLogger)
Gitlab::Geo::Logger.extend(Gitlab::Geo::Logger::StdoutLogger)
end
Gitlab::Geo::LogCursor::Daemon.new(options).run!
......
......@@ -3,6 +3,12 @@
module Gitlab
module Geo
class Logger < ::Gitlab::JsonLogger
module StdoutLogger
def full_log_path
$stdout
end
end
def self.file_name_noext
'geo'
end
......
require 'spec_helper'
describe Gitlab::Geo::LogCursor::Logger do
describe Gitlab::Geo::LogCursor::Logger, :geo do
class LoggerSpec; end
subject(:logger) { described_class.new(LoggerSpec) }
......@@ -39,4 +39,16 @@ describe Gitlab::Geo::LogCursor::Logger do
logger.event_info(Time.now, 'Test')
end
end
context 'when class is extended with StdoutLogger' do
it 'logs to stdout' do
message = 'this message should appear on stdout'
Gitlab::Geo::Logger.extend(Gitlab::Geo::Logger::StdoutLogger)
# This is needed because otherwise https://gitlab.com/gitlab-org/gitlab-ee/blob/master/config/environments/test.rb#L52
# sets the default logging level to :fatal when running under CI
allow(Rails.logger).to receive(:level).and_return(:info)
expect { logger.info(message) }.to output(/#{message}/).to_stdout
end
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