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

json_logger.rb « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7dbedef44ee906ee25eb299695d4358045fa6392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# frozen_string_literal: true
require 'labkit/logging'

module Gitlab
  class JsonLogger < ::Labkit::Logging::JsonLogger
    class << self
      def file_name_noext
        raise NotImplementedError, "JsonLogger implementations must provide file_name_noext implementation"
      end

      def file_name
        file_name_noext + ".log"
      end

      def debug(message)
        build.debug(message)
      end

      def error(message)
        build.error(message)
      end

      def warn(message)
        build.warn(message)
      end

      def info(message)
        build.info(message)
      end

      def build
        Gitlab::SafeRequestStore[cache_key] ||=
          new(full_log_path, level: log_level)
      end

      def cache_key
        "logger:" + full_log_path.to_s
      end

      def full_log_path
        Rails.root.join("log", file_name)
      end
    end

    private

    # Override Labkit's default impl, which uses the default Ruby platform json module.
    def dump_json(data)
      Gitlab::Json.dump(data)
    end
  end
end