Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-20 22:50:20 +0300
committerStan Hu <stanhu@gmail.com>2018-07-20 22:50:20 +0300
commit477f9ed78f8a50afe8ca824436ab7c0b4475e930 (patch)
tree40c0108792fdae070212800a66846dcb136afece /spec
parent3873617548c03359e4fb9e093d181a7d61f642c4 (diff)
Bring JsonLogger to CE
This backports a module that was in EE for Geo so that other modules can have structured logging support.
Diffstat (limited to 'spec')
-rw-r--r--spec/lib/gitlab/json_logger_spec.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/lib/gitlab/json_logger_spec.rb b/spec/lib/gitlab/json_logger_spec.rb
new file mode 100644
index 00000000000..0a62785f880
--- /dev/null
+++ b/spec/lib/gitlab/json_logger_spec.rb
@@ -0,0 +1,29 @@
+# coding: utf-8
+require 'spec_helper'
+
+describe Gitlab::JsonLogger do
+ subject { described_class.new('/dev/null') }
+
+ let(:now) { Time.now }
+
+ describe '#format_message' do
+ it 'formats strings' do
+ output = subject.format_message('INFO', now, 'test', 'Hello world')
+ data = JSON.parse(output)
+
+ expect(data['severity']).to eq('INFO')
+ expect(data['time']).to eq(now.utc.iso8601(3))
+ expect(data['message']).to eq('Hello world')
+ end
+
+ it 'formats hashes' do
+ output = subject.format_message('INFO', now, 'test', { hello: 1 })
+ data = JSON.parse(output)
+
+ expect(data['severity']).to eq('INFO')
+ expect(data['time']).to eq(now.utc.iso8601(3))
+ expect(data['hello']).to eq(1)
+ expect(data['message']).to be_nil
+ end
+ end
+end