<commit_before>require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/module/aliasing'
require 'logger'

module Travis
  module Logging
    autoload :Format, 'travis/support/logging/format'

    class << self
      def included(base)
        base.extend(ClassMethods)
      end

      delegate :logger, :to => Travis

      def configure(logger)
        logger.tap do
          logger.formatter = proc { |*args| Format.format(*args) }
          logger.level = Logger.const_get(:debug.to_s.upcase) # TODO set from Travis::Worker.config or something
        end
      end

      def before(type, *args)
        logger.send(type || :info, Format.before(*args))
      end

      def after(type, *args)
        logger.send(type || :debug, Format.after(*args))
      end
    end

    delegate :logger, :to => Travis

    [:fatal, :error, :warn, :info, :debug].each do |level|
      define_method(level) do |message, options|
        logger.send(level, Logging::Format.wrap(self, message, options || {}))
      end
    end

    def log_exception(exception)
      logger.error(Logging::Format.exception(exception))
    end

    def log_header
      self.class.log_header ? instance_eval(&self.class.log_header) : self.class.name.split('::').last.downcase
    end

    module ClassMethods
      def log_header(&block)
        block ? @log_header = block : @log_header
      end

      def log(name, options = {})
        define_method(:"#{name}_with_log") do |*args, &block|
          arguments = options[:params].is_a?(FalseClass) ? [] : args
          Logging.before(options[:as], self, name, arguments) unless options[:only] == :after
          send(:"#{name}_without_log", *args, &block).tap do |result|
            Logging.after(options[:as], self, name) unless options[:only] == :before
          end
        end
        alias_method_chain name, 'log'
      end
    end<commit_msg>use 1.8 compatible block arg syntax<commit_after>require 'active_support/core_ext/module/delegation'
require 'active_support/core_ext/module/aliasing'
require 'logger'

module Travis
  module Logging
    autoload :Format, 'travis/support/logging/format'

    class << self
      def included(base)
        base.extend(ClassMethods)
      end

      delegate :logger, :to => Travis

      def configure(logger)
        logger.tap do
          logger.formatter = proc { |*args| Format.format(*args) }
          logger.level = Logger.const_get(:debug.to_s.upcase) # TODO set from Travis::Worker.config or something
        end
      end

      def before(type, *args)
        logger.send(type || :info, Format.before(*args))
      end

      def after(type, *args)
        logger.send(type || :debug, Format.after(*args))
      end
    end

    delegate :logger, :to => Travis

    [:fatal, :error, :warn, :info, :debug].each do |level|
      define_method(level) do |*args|
        message, options = *args
        logger.send(level, Logging::Format.wrap(self, message, options || {}))
      end
    end

    def log_exception(exception)
      logger.error(Logging::Format.exception(exception))
    end

    def log_header
      self.class.log_header ? instance_eval(&self.class.log_header) : self.class.name.split('::').last.downcase
    end

    module ClassMethods
      def log_header(&block)
        block ? @log_header = block : @log_header
      end

      def log(name, options = {})
        define_method(:"#{name}_with_log") do |*args, &block|
          arguments = options[:params].is_a?(FalseClass) ? [] : args
          Logging.before(options[:as], self, name, arguments) unless options[:only] == :after
          send(:"#{name}_without_log", *args, &block).tap do |result|
            Logging.after(options[:as], self, name) unless options[:only] == :before
          end
        end
        alias_method_chain name, 'log'
      end
    end
{'fraction_non_alphanumeric': 0.12797927461139896, 'fraction_numerical': 0.0005181347150259067, 'mean_word_length': 2.7125, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7365082', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1154, 'n_words': 268}