<commit_before>require "rails/railtie"
require "ooor/rack"

module Ooor
  class Railtie < Rails::Railtie
    initializer "ooor.middleware" do |app|
      Ooor.logger = Rails.logger unless $0 != 'irb'
      Ooor.logger.level = @config[:log_level] if @config[:log_level]
      Ooor.default_config = load_config(false, Rails.env)
      connection = Ooor.session_handler.retrieve_session(Ooor.default_config)

      if Ooor.default_config[:bootstrap]
        connection.global_login(config)
      end
      unless Ooor.default_config[:disable_locale_switcher]
        if defined?(Rack::I18nLocaleSwitcher)
          app.middleware.use '::Rack::I18nLocaleSwitcher'
        else
          puts "Could not load Rack::I18nLocaleSwitcher, if your application is internationalized, make sure to include rack-i18n_locale_switcher in your Gemfile"
        end
      end
      app.middleware.insert_after ActionDispatch::ParamsParser, '::Ooor::Rack'
    end

    def load_config(config_file=nil, env=nil)
      config_file ||= defined?(Rails.root) && "#{Rails.root}/config/ooor.yml" || 'ooor.yml'
      @config = HashWithIndifferentAccess.new(YAML.load_file(config_file)[env || 'development'])
    rescue SystemCallError
      puts """failed to load OOOR yaml configuration file.
         make sure your app has a #{config_file} file correctly set up
         if not, just copy/paste the default ooor.yml file from the OOOR Gem
         to #{Rails.root}/config/ooor.yml and customize it properly\n\n"""
      {}
    end
  end
end<commit_msg>better logger usage<commit_after>require "rails/railtie"
require "ooor/rack"

module Ooor
  class Railtie < Rails::Railtie
    initializer "ooor.middleware" do |app|
      Ooor.logger = Rails.logger unless $0 != 'irb'
      Ooor.default_config = load_config(false, Rails.env)
      Ooor.logger.level = @config[:log_level] if @config[:log_level]
      connection = Ooor.session_handler.retrieve_session(Ooor.default_config)

      if Ooor.default_config[:bootstrap]
        connection.global_login(config)
      end
      unless Ooor.default_config[:disable_locale_switcher]
        if defined?(Rack::I18nLocaleSwitcher)
          app.middleware.use '::Rack::I18nLocaleSwitcher'
        else
          puts "Could not load Rack::I18nLocaleSwitcher, if your application is internationalized, make sure to include rack-i18n_locale_switcher in your Gemfile"
        end
      end
      app.middleware.insert_after ActionDispatch::ParamsParser, '::Ooor::Rack'
    end

    def load_config(config_file=nil, env=nil)
      config_file ||= defined?(Rails.root) && "#{Rails.root}/config/ooor.yml" || 'ooor.yml'
      @config = HashWithIndifferentAccess.new(YAML.load_file(config_file)[env || 'development'])
    rescue SystemCallError
      Ooor.logger.error """failed to load OOOR yaml configuration file.
         make sure your app has a #{config_file} file correctly set up
         if not, just copy/paste the default ooor.yml file from the OOOR Gem
         to #{Rails.root}/config/ooor.yml and customize it properly\n\n"""
      {}
    end
  end
end
{'fraction_non_alphanumeric': 0.10211382113821138, 'fraction_numerical': 0.005853658536585366, 'mean_word_length': 3.413199426111908, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5174223', 'n_tokens_mistral': 995, 'n_tokens_neox': 966, 'n_words': 229}