Sha256: 88a9c98e575a6452029a1a0c0027f8411146a99adbb3aff92edc830c05e6d053

Contents?: true

Size: 699 Bytes

Versions: 1

Compression:

Stored size: 699 Bytes

Contents

# frozen_string_literal: true

require_relative "custom_formatter/version"
require 'ddtrace'
module CustomFormatter
  class Formatter < ActiveSupport::Logger::SimpleFormatter
    def initialize(opt = {}, colorize_logging = true)
      @option = opt
      ActiveSupport::LogSubscriber.colorize_logging = colorize_logging
    end

    def call(severity, _time, _progname, msg)
      trace = trace = Datadog::Tracing.log_correlation.scan(/dd\.(\w+)=(\w+)/).to_h
      custom_format = {
        date: Time.now.strftime("%Y-%m-%dT%H:%M:%S.%L%:z"),
        log: {
          level: severity
        },
        message: msg,
        dd: trace
      }
      JSON.dump(custom_format) + "\n"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
custom_formatter-0.1.0 lib/custom_formatter.rb