<commit_before>module Rpush
  class Logger
    def initialize
      FileUtils.mkdir_p(File.dirname(Rpush.config.log_file))
      log = File.open(Rpush.config.log_file, 'a')
      log.sync = true
      setup_logger(log)
    rescue Errno::ENOENT, Errno::EPERM => e
      @logger = nil
      error(e)
      error('Logging disabled.')
    end

    def info(msg, inline = false)
      log(:info, msg, inline)
    end

    def error(msg, inline = false)
      log(:error, msg, inline, 'ERROR', STDERR)
    end

    def warn(msg, inline = false)
      log(:warn, msg, inline, 'WARNING', STDERR)
    end

    private

    def setup_logger(log)
      if Rpush.config.logger
        @logger = Rpush.config.logger
      elsif ActiveSupport.const_defined?('BufferedLogger')
        @logger = ActiveSupport::BufferedLogger.new(log, Rpush.config.log_level)
        @logger.auto_flushing = auto_flushing
      else
        @logger = ActiveSupport::Logger.new(log, Rpush.config.log_level)<commit_msg>Avoid opening rpush.log if a custom logger is present.<commit_after>module Rpush
  class Logger
    def initialize
      if Rpush.config.logger
        @logger = Rpush.config.logger
      else
        FileUtils.mkdir_p(File.dirname(Rpush.config.log_file))
        log = File.open(Rpush.config.log_file, 'a')
        log.sync = true
        @logger = setup_logger(log)
      end
    rescue Errno::ENOENT, Errno::EPERM => e
      @logger = nil
      error(e)
      error('Logging disabled.')
    end

    def info(msg, inline = false)
      log(:info, msg, inline)
    end

    def error(msg, inline = false)
      log(:error, msg, inline, 'ERROR', STDERR)
    end

    def warn(msg, inline = false)
      log(:warn, msg, inline, 'WARNING', STDERR)
    end

    private

    def setup_logger(log)
      if ActiveSupport.const_defined?('BufferedLogger')
        logger = ActiveSupport::BufferedLogger.new(log, Rpush.config.log_level)
        logger.auto_flushing = auto_flushing
        logger
      else
        ActiveSupport::Logger.new(log, Rpush.config.log_level)
{'fraction_non_alphanumeric': 0.109375, 'fraction_numerical': 0.0, 'mean_word_length': 2.632978723404255, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5353073', 'n_tokens_mistral': 663, 'n_tokens_neox': 651, 'n_words': 148}