diff options
author | Stan Hu <stanhu@gmail.com> | 2018-07-20 22:50:20 +0300 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-07-20 22:50:20 +0300 |
commit | 477f9ed78f8a50afe8ca824436ab7c0b4475e930 (patch) | |
tree | 40c0108792fdae070212800a66846dcb136afece /lib/gitlab/json_logger.rb | |
parent | 3873617548c03359e4fb9e093d181a7d61f642c4 (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 'lib/gitlab/json_logger.rb')
-rw-r--r-- | lib/gitlab/json_logger.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/gitlab/json_logger.rb b/lib/gitlab/json_logger.rb new file mode 100644 index 00000000000..28e258196ca --- /dev/null +++ b/lib/gitlab/json_logger.rb @@ -0,0 +1,22 @@ +module Gitlab + class JsonLogger < ::Gitlab::Logger + def self.file_name_noext + raise NotImplementedError + end + + def format_message(severity, timestamp, progname, message) + data = {} + data[:severity] = severity + data[:time] = timestamp.utc.iso8601(3) + + case message + when String + data[:message] = message + when Hash + data.merge!(message) + end + + data.to_json + "\n" + end + end +end |