summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2018-03-15 11:33:50 +0100
committerJacob Vosmaer <jacob@gitlab.com>2018-03-15 11:33:50 +0100
commite087f81af667946fd5ec5468b64e6d9f8c6f88ed (patch)
tree550721a0a5f9dbd04f63e187a305d1f8d2c1725f
parentb46eccf0e6be0e6621806c1062dc452dec9d5645 (diff)
downloadgitlab-shell-e087f81af667946fd5ec5468b64e6d9f8c6f88ed.tar.gz
Sort like logrus
-rw-r--r--lib/gitlab_logger.rb2
-rw-r--r--spec/gitlab_logger_spec.rb9
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/gitlab_logger.rb b/lib/gitlab_logger.rb
index eba592c..cdca25b 100644
--- a/lib/gitlab_logger.rb
+++ b/lib/gitlab_logger.rb
@@ -79,7 +79,7 @@ class GitlabLogger
format_key_value(:msg, data.delete(:msg))
]
- data.each { |k, v| result << format_key_value(k, v) }
+ data.sort.each { |k, v| result << format_key_value(k, v) }
result.join(' ')
end
diff --git a/spec/gitlab_logger_spec.rb b/spec/gitlab_logger_spec.rb
index 48e3623..741ee13 100644
--- a/spec/gitlab_logger_spec.rb
+++ b/spec/gitlab_logger_spec.rb
@@ -28,6 +28,15 @@ describe GitlabLogger do
output.string.lines.first.chomp
end
+ describe 'field sorting' do
+ it 'sorts fields, except time, level, msg' do
+ # Intentionally put 'foo' before 'baz' to see the effect of sorting
+ subject.info('hello world', foo: 'bar', baz: 'qux')
+
+ expect(first_line).to eq('time="1973-11-29T21:33:09+00:00" level=info msg="hello world" baz=qux foo=bar pid=1234')
+ end
+ end
+
describe '#info' do
context 'when the log level is too high' do
let(:level) { Logger::ERROR }