<commit_before>require 'managedthreads'

module Module::Requirements::Feature::Logging
  extend Module::Requirements

  @@logging_queue ||= Queue.new

  class Logger
    def self.<<(message)
      info message, tag: "Logger"
    end
  end

  class ThreadLessLog
    define_method :<< do |(level,message,keys)|
      message.each do |m|
        CCCB.instance.debug_print level, m, **keys
      end
    end

    def pop(*args)
      sleep 1
    end

    def empty?
      true
    end
  end

  needs :static_methods

  def caller_map
    string = ""
    caller_locations(2).reverse.each_with_object([]) do |l,a|
      a << ( string += ";#{l.label}:#{l.lineno}" ).dup
    end
  end

  def log?(level)
    log_level = CCCB.instance.logging.loglevel||DEBUG

    if by_level = CCCB.instance.logging.loglevel_by_label
      locations = caller_locations
      return false unless log_level >= level or by_level.any? { |k,v| 
        next unless v.respond_to? :to_sym
        level_for_k = self.class.const_get( v.to_sym )
        locations.any? { |l| 
          #p lo: locations.map(&:label), k: k, L: level_for_k, LEVEL: level if l.label == k
          l.label == k and level_for_k >= level 
        } 
      }
    else
      return false unless log_level >= level
    end
  
    true
  end

  DEBUG_LEVELS = %i( CRITICAL ERROR WARNING INFO VERBOSE DEBUG SPAM DETAIL )<commit_msg>Logging refactor: More detail levels<commit_after>require 'managedthreads'

module Module::Requirements::Feature::Logging
  extend Module::Requirements

  @@logging_queue ||= Queue.new

  class Logger
    def self.<<(message)
      info message, tag: "Logger"
    end
  end

  class ThreadLessLog
    define_method :<< do |(level,message,keys)|
      message.each do |m|
        CCCB.instance.debug_print level, m, **keys
      end
    end

    def pop(*args)
      sleep 1
    end

    def empty?
      true
    end
  end

  needs :static_methods

  def caller_map
    string = ""
    caller_locations(2).reverse.each_with_object([]) do |l,a|
      a << ( string += ";#{l.label}:#{l.lineno}" ).dup
    end
  end

  def log?(level)
    log_level = CCCB.instance.logging.loglevel||DEBUG

    if by_level = CCCB.instance.logging.loglevel_by_label
      locations = caller_locations
      return false unless log_level >= level or by_level.any? { |k,v| 
        next unless v.respond_to? :to_sym
        level_for_k = self.class.const_get( v.to_sym )
        locations.any? { |l| 
          #p lo: locations.map(&:label), k: k, L: level_for_k, LEVEL: level if l.label == k
          l.label == k and level_for_k >= level 
        } 
      }
    else
      return false unless log_level >= level
    end
  
    true
  end

  DEBUG_LEVELS = %i( CRITICAL ERROR WARNING INFO VERBOSE DEBUG SPAM DETAIL DETAIL2 DETAIL3 DETAIL4 DETAIL5 )
{'fraction_non_alphanumeric': 0.1068238656663094, 'fraction_numerical': 0.0028581636298678098, 'mean_word_length': 2.5398230088495577, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, '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': '3821225', 'n_tokens_mistral': 966, 'n_tokens_neox': 925, 'n_words': 244}