Sha256: 630c5724e1e5aaa237e7af576fec8108c97eccd4a637fd1fb28991cc08d95028

Contents?: true

Size: 746 Bytes

Versions: 7

Compression:

Stored size: 746 Bytes

Contents

require 'jbuilder'
require_relative 'log_formatter_base'
require_relative 'severity_level'

module RTALogger
  # json formatter which receive log_record and
  # returns it's data as json string
  class LogFormatterJson < LogFormatterBase
    include SeverityLevel

    def format(log_record)
      return '' unless log_record

      jb = Jbuilder.new do |json|
        json.occurred_at log_record.occurred_at.strftime('%F %H:%M:%S:%3N')
        json.app_name log_record.app_name
        json.topic_title log_record.topic_title
        json.context_id log_record.context_id
        json.severity parse_severity_level_to_s(log_record.severity)
        json.message log_record.message.flatten.join(' ')
      end

      jb.target!
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
RTALogger-2.1.2 lib/log_formatter_json.rb
RTALogger-2.1.1 lib/log_formatter_json.rb
RTALogger-2.1.0 lib/log_formatter_json.rb
RTALogger-2.0.2 lib/log_formatter_json.rb
RTALogger-2.0.1 lib/log_formatter_json.rb
RTALogger-2.0.0 lib/log_formatter_json.rb
RTALogger-1.1.1 lib/log_formatter_json.rb