<commit_before>require "multi_json"
require "socket"

#
# Simple formatter to output error messages as JSON.
#
module Sysloggly
  module Formatters
    class SimpleFormatter
      attr_reader :input_uri, :custom_fields

      def initialize(input_uri, opts = {})
        @input_uri = input_uri

        @env = opts[:env] || Sysloggly.env
        @hostname = opts[:hostname] || Socket.gethostname.split(".").first
        @progname = opts[:progname]
        @custom_fields = opts.except(:progname).merge({
          env: @env,
          hostname: @hostname
        })

        if ["udp", "tcp"].include?(@input_uri.scheme) && !@input_uri.path.empty?
          if @facility = @input_uri.path.split("/")[1]
            @facility = @facility.to_i
            unless @facility <= 23 && @facility >= 0
              raise Sysloggly::UnknownFacility.new(@facility.to_s)
            end
          end
        else
          @facility = 23
        end
      end

      # Specifies the date/time format for this client
      #
      # @api public
      def datetime_format
        "%b %e %H:%M:%S"
      end

      # @api public
      def call(severity, datetime, progname, payload)
        message = "#{severity} [#{datetime.strftime(datetime_format)}] "<commit_msg>log +app (progname) as JSON field<commit_after>require "multi_json"
require "socket"

#
# Simple formatter to output error messages as JSON.
#
module Sysloggly
  module Formatters
    class SimpleFormatter
      attr_reader :input_uri, :custom_fields

      def initialize(input_uri, opts = {})
        @input_uri = input_uri

        @env = opts[:env] || Sysloggly.env
        @hostname = opts[:hostname] || Socket.gethostname.split(".").first
        @progname = opts[:progname].to_s.downcase
        @custom_fields = opts.except(:progname).merge({
          app: @progname,
          env: @env,
          hostname: @hostname
        })

        if ["udp", "tcp"].include?(@input_uri.scheme) && !@input_uri.path.empty?
          if @facility = @input_uri.path.split("/")[1]
            @facility = @facility.to_i
            unless @facility <= 23 && @facility >= 0
              raise Sysloggly::UnknownFacility.new(@facility.to_s)
            end
          end
        else
          @facility = 23
        end
      end

      # Specifies the date/time format for this client
      #
      # @api public
      def datetime_format
        "%b %e %H:%M:%S"
      end

      # @api public
      def call(severity, datetime, progname, payload)
        message = "#{severity} [#{datetime.strftime(datetime_format)}] "
{'fraction_non_alphanumeric': 0.12276612276612277, 'fraction_numerical': 0.004662004662004662, 'mean_word_length': 2.194789081885856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1074761', 'n_tokens_mistral': 811, 'n_tokens_neox': 780, 'n_words': 183}