<commit_before>module RailsGraylogger
  class Logger
    FIELD_KEY_REGEXP = /^[\w\.\-]*$/

    def initialize(logger)
      @logger = logger
    end

    class << self
      def initialize_log_buffer
        RequestStore.store[:graylog2_buffer] = []
      end

      def request_tags
        RequestStore.store[:graylog2_tags] ||= []
      end

      def request_buffer
        RequestStore.store[:graylog2_buffer]
      end
    end

    def tagged(*new_tags, &block)
      new_tags = Array.wrap(new_tags).flatten.reject(&:blank?)
      self.class.request_tags << new_tags - ( self.class.request_tags & new_tags )
      @logger.send("tagged", *new_tags, &block)
    end

    private

    def method_missing(method, *args, &block)
      if [:add, :info, :debug, :warn, :error, :fatal].include?(method) && !args[0].nil?
        if args.size == 1 && args[0].is_a?(String)
          hash = { short_message: args[0] }
        else
          return if args.blank?
          hash = {}
          args.compact.each { |arg| hash.merge!(arg) }
          hash = { short_message: hash.inspect }
        end

        unless self.class.request_buffer.nil?
          self.class.request_buffer << hash
        else
          notify!(method, hash)
        end
      end
      @logger.send(method, *args, &block)<commit_msg>Fix handling of non-string arguments<commit_after>module RailsGraylogger
  class Logger
    FIELD_KEY_REGEXP = /^[\w\.\-]*$/

    def initialize(logger)
      @logger = logger
    end

    class << self
      def initialize_log_buffer
        RequestStore.store[:graylog2_buffer] = []
      end

      def request_tags
        RequestStore.store[:graylog2_tags] ||= []
      end

      def request_buffer
        RequestStore.store[:graylog2_buffer]
      end
    end

    def tagged(*new_tags, &block)
      new_tags = Array.wrap(new_tags).flatten.reject(&:blank?)
      self.class.request_tags << new_tags - ( self.class.request_tags & new_tags )
      @logger.send("tagged", *new_tags, &block)
    end

    private

    def method_missing(method, *args, &block)
      if [:add, :info, :debug, :warn, :error, :fatal].include?(method) && !args[0].nil?
        if args.size == 1 && args[0].is_a?(String)
          hash = { short_message: args[0] }
        else
          return if args.blank?
          hash = { short_message: args.compact.map(&:to_s).join("\n") }
        end

        unless self.class.request_buffer.nil?
          self.class.request_buffer << hash
        else
          notify!(method, hash)
        end
      end
      @logger.send(method, *args, &block)
{'fraction_non_alphanumeric': 0.1274699728787292, 'fraction_numerical': 0.005424254165052305, 'mean_word_length': 2.2437185929648242, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3197168', 'n_tokens_mistral': 837, 'n_tokens_neox': 805, 'n_words': 165}