Class: Gitlab::JsonLogger

Inherits:
Logger
  • Object
show all
Defined in:
lib/gitlab/json_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Logger

build, cache_key, debug, error, file_name, full_log_path, info, read_latest, warn

Class Method Details

.file_name_noextObject

Raises:

  • (NotImplementedError)

5
6
7
# File 'lib/gitlab/json_logger.rb', line 5

def self.file_name_noext
  raise NotImplementedError
end

Instance Method Details

#format_message(severity, timestamp, progname, message) ⇒ Object


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/gitlab/json_logger.rb', line 9

def format_message(severity, timestamp, progname, message)
  data = {}
  data[:severity] = severity
  data[:time] = timestamp.utc.iso8601(3)
  data[Labkit::Correlation::CorrelationId::LOG_KEY] = Labkit::Correlation::CorrelationId.current_id

  case message
  when String
    data[:message] = message
  when Hash
    data.merge!(message)
  end

  Gitlab::Json.dump(data) + "\n"
end