Sha256: 6566037006558e79b791b4b27b19cf05c7b676fba660a9e51939c50653329bf0

Contents?: true

Size: 743 Bytes

Versions: 3

Compression:

Stored size: 743 Bytes

Contents

require 'json'

module SemanticLogger
  module Formatters
    # Fluentd is similar to SemanticLogger::Formatters::Json but with log levels that are recognized
    # by kubernetes fluentd.
    class Fluentd < Json
      attr_reader :need_process_info

      def initialize(time_format: :rfc_3339, time_key: :time, need_process_info: false, **args)
        @need_process_info = need_process_info
        super(time_format: time_format, time_key: time_key, **args)
      end

      def level
        hash['severity']       = log.level
        hash['severity_index'] = log.level_index
      end

      def process_info
        # Ignore fields: pid, thread, file and line by default
        super() if need_process_info
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
semantic_logger-4.6.1 lib/semantic_logger/formatters/fluentd.rb
semantic_logger-4.6.0 lib/semantic_logger/formatters/fluentd.rb
semantic_logger-4.6.0.beta1 lib/semantic_logger/formatters/fluentd.rb