<commit_before>require 'logger'
require 'singleton'
require 'delegate'

module Honeybadger
  module Logging
    PREFIX = '** [Honeybadger] '.freeze

    # Internal: Logging helper methods. Requires a Honeybadger::Config @config
    # instance variable to exist and/or #debug? and #logger to be defined. Each
    # method is defined/block captured in this module rather than delegating to
    # the logger directly to avoid extra object allocation.
    module Helper
      def debug(msg = nil)
        return unless debug?
        msg = yield if block_given?
        logger.debug(msg)
      end
      alias :d :debug

      def info(msg = nil)
        return if Logger::Severity::INFO < logger.level
        msg = yield if block_given?
        logger.info(msg)
      end

      def warn(msg = nil)
        return if Logger::Severity::WARN < logger.level
        msg = yield if block_given?
        logger.warn(msg)
      end

      def error(msg = nil)
        return if Logger::Severity::ERROR < logger.level
        msg = yield if block_given?
        logger.error(msg)
      end

      def debug?
        @config.debug?
      end

      def logger
        @config.logger
      end
    end

    class Base
      Logger::Severity.constants.each do |severity|
        define_method severity.downcase do |msg|
          add(Logger::Severity.const_get(severity), msg)
        end
      end

      def add(severity, msg)
        raise NotImplementedError, 'must define #add on subclass.'
      end

      def level
        Logger::Severity::Debug
      end
    end

    class FormattedLogger < Base
      def initialize(logger = Logger.new('/dev/null'))
        raise ArgumentError, 'logger not specified' unless logger
        raise ArgumentError, 'logger must be a logger' unless logger.respond_to?(:add)

        @logger = logger
      end

      def add(severity, msg)
        @logger.add(severity, format(msg))
      end

      def level
        @logger.level
      end

      private

      def format(msg)
        return msg unless msg.kind_of?(String)
        PREFIX + msg
      end
    end

    class BootLogger < Base
      include Singleton

      def initialize
        @messages = []
      end

      def add(severity, msg)<commit_msg>On second thought...<commit_after>require 'logger'
require 'singleton'
require 'delegate'

module Honeybadger
  module Logging
    PREFIX = '** [Honeybadger] '.freeze

    # Internal: Logging helper methods. Requires a Honeybadger::Config @config
    # instance variable to exist and/or #debug? and #logger to be defined. Each
    # method is defined/block captured in this module rather than delegating to
    # the logger directly to avoid extra object allocation.
    module Helper
      def debug(msg = nil)
        return unless debug?
        msg = yield if block_given?
        logger.debug(msg)
      end
      alias :d :debug

      def info(msg = nil)
        return if Logger::Severity::INFO < logger.level
        msg = yield if block_given?
        logger.info(msg)
      end

      def warn(msg = nil)
        return if Logger::Severity::WARN < logger.level
        msg = yield if block_given?
        logger.warn(msg)
      end

      def error(msg = nil)
        return if Logger::Severity::ERROR < logger.level
        msg = yield if block_given?
        logger.error(msg)
      end

      def debug?
        @config.debug?
      end

      def logger
        @config.logger
      end
    end

    class Base
      Logger::Severity.constants.each do |severity|
        define_method severity.downcase do |msg|
          add(Logger::Severity.const_get(severity), msg)
        end
      end

      def add(severity, msg)
        raise NotImplementedError, 'must define #add on subclass.'
      end

      def level
        Logger::Severity::Debug
      end
    end

    class FormattedLogger < Base
      def initialize(logger = Logger.new('/dev/null'))
        raise ArgumentError, 'logger not specified' unless logger
        raise ArgumentError, 'logger must be a logger' unless logger.respond_to?(:add)

        @logger = logger
      end

      def add(severity, msg)
        @logger.add(severity, format_message(msg))
      end

      def level
        @logger.level
      end

      private

      def format_message(msg)
        return msg unless msg.kind_of?(String)
        PREFIX + msg
      end
    end

    class BootLogger < Base
      include Singleton

      def initialize
        @messages = []
      end

      def add(severity, msg)
{'fraction_non_alphanumeric': 0.07692307692307693, 'fraction_numerical': 0.0, 'mean_word_length': 2.0652173913043477, 'pattern_counts': {'":': 0, '<': 13, '<?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': '5293996', 'n_tokens_mistral': 1312, 'n_tokens_neox': 1240, 'n_words': 409}