Commit 9087e960 authored by Jacob Vosmaer (GitLab)'s avatar Jacob Vosmaer (GitLab) Committed by Douwe Maan

Flush log file after every write

parent e19b08ba
v7.1.1
- Flush log file after every write (!199)
v7.1.0 v7.1.0
- Migrate `git-upload-archive` to gitaly - Migrate `git-upload-archive` to gitaly
......
#!/usr/bin/env ruby
# The purpose of this executable is to test that gitlab-shell logging
# works correctly in combination with Kernel.exec.
require_relative '../lib/gitlab_init'
require_relative '../lib/gitlab_logger'
$logger.info(ARGV.first)
Kernel.exec('true')
...@@ -25,7 +25,13 @@ class GitlabLogger ...@@ -25,7 +25,13 @@ class GitlabLogger
def initialize(level, path, log_format) def initialize(level, path, log_format)
@level = level @level = level
@log_file = File.open(path, 'ab') @log_file = File.open(path, 'ab')
# By default Ruby will buffer writes. This is a problem when we exec
# into a new command before Ruby flushed its buffers. Setting 'sync' to
# true disables Ruby's buffering.
@log_file.sync = true
@log_format = log_format @log_format = log_format
end end
......
require_relative 'spec_helper' require_relative 'spec_helper'
require_relative '../lib/gitlab_logger' require_relative '../lib/gitlab_logger'
require 'securerandom'
describe :convert_log_level do describe :convert_log_level do
subject { convert_log_level :extreme } subject { convert_log_level :extreme }
...@@ -112,4 +113,15 @@ describe GitlabLogger do ...@@ -112,4 +113,15 @@ describe GitlabLogger do
expect(JSON.parse(first_line)).to include('msg' => '"hello\x80world"') expect(JSON.parse(first_line)).to include('msg' => '"hello\x80world"')
end end
end end
describe 'log flushing' do
it 'logs get written even when calling Kernel.exec' do
msg = SecureRandom.hex(12)
test_logger_status = system('bin/test-logger', msg)
expect(test_logger_status).to eq(true)
grep_status = system('grep', '-q', '-e', msg, GitlabConfig.new.log_file)
expect(grep_status).to eq(true)
end
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