From 95e292780492ea764328566503ebefcae8a170f3 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 11 Sep 2018 22:55:01 -0700 Subject: 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 --- lib/gitlab_logger.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/gitlab_logger.rb b/lib/gitlab_logger.rb index ed169f7..67f6030 100644 --- a/lib/gitlab_logger.rb +++ b/lib/gitlab_logger.rb @@ -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 -- cgit v1.2.1