<commit_before>require 'erb'
require 'mongo'
require 'active_support'
require 'active_support/core_ext'
require 'mongodb_logger/replica_set_helper'

module MongodbLogger
  class Logger < ActiveSupport::BufferedLogger
    include ReplicaSetHelper

    DEFAULT_COLLECTION_SIZE = 250.megabytes
    # Looks for configuration files in this order
    CONFIGURATION_FILES = ["mongodb_logger.yml", "mongoid.yml", "database.yml"]
    LOG_LEVEL_SYM = [:debug, :info, :warn, :error, :fatal, :unknown]

    attr_reader :db_configuration, :mongo_connection, :mongo_collection_name, :mongo_collection

    def initialize(options={})
      path = options[:path] || File.join(Rails.root, "log/#{Rails.env}.log")
      level = options[:level] || DEBUG
      internal_initialize
    rescue => e
      # should use a config block for this
      Rails.env.production? ? (raise e) : (puts "!!! MongodbLoggerError:  Using BufferedLogger due to exception: " + e.message)
    ensure
      if disable_file_logging?
        @level          = level
        @buffer         = {}
        @auto_flushing  = 1
        @guard          = Mutex.new
      else
        super(path, level)
      end
    end

    def add_metadata(options={})
      options.each do |key, value|
        unless [:messages, :request_time, :ip, :runtime, :application_name, :is_exception, :params, :method].include?(key.to_sym)
          @mongo_record[key] = value
        else
          raise ArgumentError, ":#{key} is a reserved key for the mongodb logger. Please choose a different key"
        end
      end<commit_msg>fix error message in logger<commit_after>require 'erb'
require 'mongo'
require 'active_support'
require 'active_support/core_ext'
require 'mongodb_logger/replica_set_helper'

module MongodbLogger
  class Logger < ActiveSupport::BufferedLogger
    include ReplicaSetHelper

    DEFAULT_COLLECTION_SIZE = 250.megabytes
    # Looks for configuration files in this order
    CONFIGURATION_FILES = ["mongodb_logger.yml", "mongoid.yml", "database.yml"]
    LOG_LEVEL_SYM = [:debug, :info, :warn, :error, :fatal, :unknown]

    attr_reader :db_configuration, :mongo_connection, :mongo_collection_name, :mongo_collection

    def initialize(options={})
      path = options[:path] || File.join(Rails.root, "log/#{Rails.env}.log")
      level = options[:level] || DEBUG
      internal_initialize
    rescue => e
      # should use a config block for this
      Rails.env.production? ? (raise e) : (puts "MongodbLogger WARNING: Using BufferedLogger due to exception: " + e.message)
    ensure
      if disable_file_logging?
        @level          = level
        @buffer         = {}
        @auto_flushing  = 1
        @guard          = Mutex.new
      else
        super(path, level)
      end
    end

    def add_metadata(options={})
      options.each do |key, value|
        unless [:messages, :request_time, :ip, :runtime, :application_name, :is_exception, :params, :method].include?(key.to_sym)
          @mongo_record[key] = value
        else
          raise ArgumentError, ":#{key} is a reserved key for the mongodb logger. Please choose a different key"
        end
      end
{'fraction_non_alphanumeric': 0.10400763358778627, 'fraction_numerical': 0.002544529262086514, 'mean_word_length': 3.0528350515463916, 'pattern_counts': {'":': 2, '<': 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': '491414', 'n_tokens_mistral': 973, 'n_tokens_neox': 944, 'n_words': 250}