<commit_before>module ImportOMmatic

  class Logger < ::Logger
    attr_accessor :counters

    def format_message(severity, timestamp, progname, msg)
      "#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
    end

    def initialize object_name
      object_name.gsub!('/', '_')
      self.counters = {}
      import_path = "log/importations/#{object_name}"
      FileUtils.mkdir_p(import_path) unless File.directory?(import_path)
      timestamp = Time.now.utc.iso8601.gsub(/\W/, '')
      file_name = "#{timestamp}_#{object_name}_import.log"
      super "#{import_path}/#{file_name}"
    end

    def finish
      self.info "---- End of importation"
      self.info "---- Results:"
      self.counters.each do |key, value|
        self.info "\t\t#{key.upcase}: #{value}" if key
      end
    end

    def counter kind
      counters[kind] = counters[kind].to_i.next
    end

    def print_errors text, item
      self.counter :errors
      self.error "-- Errors with data:"
      self.error "\t#{text}"
      self.error "\t#{item.errors.full_messages.to_sentence}"
    end
  end

end
<commit_msg>Add log path as accessor<commit_after>module ImportOMmatic

  class Logger < ::Logger
    attr_accessor :counters, :path

    def format_message(severity, timestamp, progname, msg)
      "#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
    end

    def initialize object_name
      object_name.gsub!('/', '_')
      self.counters = {}
      log_dir = "log/importations/#{object_name}"
      FileUtils.mkdir_p(log_dir) unless File.directory?(log_dir)
      timestamp = Time.now.utc.iso8601.gsub(/\W/, '')
      file_name = "#{timestamp}_#{object_name}_import.log"
      super self.path = "#{log_dir}/#{file_name}"
    end

    def finish
      self.info "---- End of importation"
      self.info "---- Results:"
      self.counters.each do |key, value|
        self.info "\t\t#{key.upcase}: #{value}" if key
      end
    end

    def counter kind
      counters[kind] = counters[kind].to_i.next
    end

    def print_errors text, item
      self.counter :errors
      self.error "-- Errors with data:"
      self.error "\t#{text}"
      self.error "\t#{item.errors.full_messages.to_sentence}"
    end
  end

end

{'fraction_non_alphanumeric': 0.14106019766397124, 'fraction_numerical': 0.0035938903863432167, 'mean_word_length': 2.668863261943987, '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': '7193260', 'n_tokens_mistral': 749, 'n_tokens_neox': 734, 'n_words': 156}