Commit 95e29278 authored by Stan Hu's avatar Stan Hu

Fix newlines not appearing between new log entries

In https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/5017, we
observed that lots of log messages were being dropped by Fluentd due to
missing newlines.

This occurs because there is a bug in Ruby where IO#puts calls write() twice:
once to write the main text, and another to write the newline
(https://bugs.ruby-lang.org/issues/14042). In a highly concurrent environment
like GitLab.com, this can lead to interleaved newlines.

A workaround is to use `IO#print` and append the newline ourselves.

Closes https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/5017
parent e5b6e8e2
......@@ -68,9 +68,10 @@ class GitlabLogger
case log_format
when 'json'
log_file.puts format_json(data)
# Don't use IO#puts because of https://bugs.ruby-lang.org/issues/14042
log_file.print("#{format_json(data)}\n")
else
log_file.puts format_text(data)
log_file.print("#{format_text(data)}\n")
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