<commit_before>require 'json'

module Semlogr
  module Formatters
    class JsonFormatter
      def format(log_event)
        entry = {
          timestamp: log_event.timestamp,
          severity: log_event.severity,
          message: render_message(log_event)
        }

        add_error(entry, log_event)
        add_properties(entry, log_event)

        "#{entry.to_json}\n"
      end

      private

      def add_error(entry, log_event)
        return unless log_event.error

        entry[:error] = {
          type: log_event.error.class,
          message: log_event.error.message,
          backtrace: log_event.error.backtrace
        }<commit_msg>Format the timestamp as iso8601 in the json formatter<commit_after>require 'json'

module Semlogr
  module Formatters
    class JsonFormatter
      def format(log_event)
        entry = {
          timestamp: log_event.timestamp.iso8601(3),
          severity: log_event.severity,
          message: render_message(log_event)
        }

        add_error(entry, log_event)
        add_properties(entry, log_event)

        "#{entry.to_json}\n"
      end

      private

      def add_error(entry, log_event)
        return unless log_event.error

        entry[:error] = {
          type: log_event.error.class,
          message: log_event.error.message,
          backtrace: log_event.error.backtrace
        }
{'fraction_non_alphanumeric': 0.07938820101966497, 'fraction_numerical': 0.0065549890750182084, 'mean_word_length': 2.1513761467889907, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4878994', 'n_tokens_mistral': 417, 'n_tokens_neox': 400, 'n_words': 82}