<commit_before>require "logger"

module Pwrake

  module Log

    module_function

    def method_missing(meth_id,*args)
      if Rake.application.logger
        Rake.application.logger.send(meth_id,*args)
      end
    end

    def bt(e)
      "#{e.class}: #{e.message}\n "+(e.backtrace||[]).join("\n ")
    end
  end
end
<commit_msg>new method: Logger.set_logger: set @@logger from option.<commit_after>require "logger"

module Pwrake

  module Log

    @@logger = nil

    module_function

    def set_logger(option)
      unless @@logger
        if logdir = option['LOG_DIR']
          ::FileUtils.mkdir_p(logdir)
          logfile = File.join(logdir, option['LOG_FILE'])
          @@logger = Logger.new(logfile)
        else
          if option['DEBUG']
            @@logger = Logger.new($stderr)
          else
            @@logger = Logger.new(File::NULL)
          end
        end

        if option['DEBUG']
          @@logger.level = Logger::DEBUG
        else
          @@logger.level = Logger::INFO
        end

        at_exit{@@logger.close}
      end
    end

    def method_missing(meth_id,*args)
      if @@logger
        @@logger.send(meth_id,*args)
      end
    end

    def bt(e)
      "#{e.class}: #{e.message}\n "+(e.backtrace||[]).join("\n ")
    end
  end
end

{'fraction_non_alphanumeric': 0.13229571984435798, 'fraction_numerical': 0.0, 'mean_word_length': 2.0401891252955084, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3701289', 'n_tokens_mistral': 431, 'n_tokens_neox': 405, 'n_words': 86}