<commit_before># Load AwesomePrint if available
begin
  require 'awesome_print'
rescue LoadError
end

module SemanticLogger
  module Formatters
    class Color < Base
      # Parameters:
      #   ap: Any valid AwesomePrint option for rendering data.
      #       These options can also be changed be creating a `~/.aprc` file.
      #       See: https://github.com/michaeldv/awesome_print
      #
      #       Note: The option :multiline is set to false if not supplied.
      #       Note: Has no effect if Awesome Print is not installed.
      def initialize(options = {})
        options     = options.dup
        @ai_options = options.delete(:ap) || {multiline: false}
        super(options)
      end

      # Adds color to the default log formatter
      # Example:
      #   SemanticLogger.add_appender(io: $stdout, formatter: :color)
      def call(log, logger)
        colors      = SemanticLogger::AnsiColors
        level_color = colors::LEVEL_MAP[log.level]

        message = time_format.nil? ? '' : "#{format_time(log.time)} "

        # Header with date, time, log level and process info
        message << "#{level_color}#{log.level_to_s}#{colors::CLEAR} [#{log.process_info}]"

        # Tags
        message << ' ' << log.tags.collect { |tag| "[#{level_color}#{tag}#{colors::CLEAR}]" }.join(' ') if log.tags && (log.tags.size > 0)

        # Named Tags
        if (named_tags = log.named_tags) && !named_tags.empty?
          list = {}
          named_tags.each_pair { |name, value| list << "[#{level_color}#{name}: #{value}#{colors::CLEAR}]" }
          message << ' ' << list.join(' ')
        end

        # Duration
        message << " (#{colors::BOLD}#{log.duration_human}#{colors::CLEAR})" if log.duration

        # Class / app name
        message << " #{level_color}#{log.name}#{colors::CLEAR}"

        # Log message
        message << " -- #{log.message}" if log.message

        # Payload: Colorize the payload if the AwesomePrint gem is loaded
        if log.has_payload?
          payload = log.payload
          message << ' -- ' <<
            if !defined?(AwesomePrint) || !payload.respond_to?(:ai)
              payload.inspect
            else
              payload.ai(@ai_options) rescue payload.inspect
            end
        end

        # Exceptions<commit_msg>Fix type typo<commit_after># Load AwesomePrint if available
begin
  require 'awesome_print'
rescue LoadError
end

module SemanticLogger
  module Formatters
    class Color < Base
      # Parameters:
      #   ap: Any valid AwesomePrint option for rendering data.
      #       These options can also be changed be creating a `~/.aprc` file.
      #       See: https://github.com/michaeldv/awesome_print
      #
      #       Note: The option :multiline is set to false if not supplied.
      #       Note: Has no effect if Awesome Print is not installed.
      def initialize(options = {})
        options     = options.dup
        @ai_options = options.delete(:ap) || {multiline: false}
        super(options)
      end

      # Adds color to the default log formatter
      # Example:
      #   SemanticLogger.add_appender(io: $stdout, formatter: :color)
      def call(log, logger)
        colors      = SemanticLogger::AnsiColors
        level_color = colors::LEVEL_MAP[log.level]

        message = time_format.nil? ? '' : "#{format_time(log.time)} "

        # Header with date, time, log level and process info
        message << "#{level_color}#{log.level_to_s}#{colors::CLEAR} [#{log.process_info}]"

        # Tags
        message << ' ' << log.tags.collect { |tag| "[#{level_color}#{tag}#{colors::CLEAR}]" }.join(' ') if log.tags && (log.tags.size > 0)

        # Named Tags
        if (named_tags = log.named_tags) && !named_tags.empty?
          list = []
          named_tags.each_pair { |name, value| list << "[#{level_color}#{name}: #{value}#{colors::CLEAR}]" }
          message << ' ' << list.join(' ')
        end

        # Duration
        message << " (#{colors::BOLD}#{log.duration_human}#{colors::CLEAR})" if log.duration

        # Class / app name
        message << " #{level_color}#{log.name}#{colors::CLEAR}"

        # Log message
        message << " -- #{log.message}" if log.message

        # Payload: Colorize the payload if the AwesomePrint gem is loaded
        if log.has_payload?
          payload = log.payload
          message << ' -- ' <<
            if !defined?(AwesomePrint) || !payload.respond_to?(:ai)
              payload.inspect
            else
              payload.ai(@ai_options) rescue payload.inspect
            end
        end

        # Exceptions
{'fraction_non_alphanumeric': 0.1283051582141309, 'fraction_numerical': 0.00043346337234503684, 'mean_word_length': 2.21602787456446, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '5886302', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1361, 'n_words': 347}