<commit_before>require 'java'
require 'time'
require 'json'
require_relative '../jars/log4j-1.2.17.jar'

module MojoLogger

  def mojo_debug(*args)
    MojoLogger.mojo_debug(*args)
  end

  def mojo_info(*args)
    MojoLogger.mojo_info(*args)
  end

  def mojo_warn(*args)
    MojoLogger.mojo_warn(*args)
  end

  def mojo_error(*args)
    MojoLogger.mojo_error(*args)
  end

  def logger
    MojoLogger.logger
  end

  class << self

    def logger
      @@logger ||= configure_logger
    end

    def mojo_msg(api_request, category, message, options=nil)
      msg = {
        'time' => Time.now.utc.strftime("%m-%d-%Y %H:%M:%S.%L %z"),
        'app' => "Mojo",
        'session_id' => api_request[:session_id],
        'reference_id' => api_request[:reference_id],
        'api' => api_request[:api],
        'category' => category,
        'message' => message
      }

      processed_opts = process_options(options)
      msg.merge!(processed_opts) if processed_opts

      msg.to_json
    end

    def mojo_debug(*args)
      logger.debug(mojo_msg(*args))
    end

    def mojo_info(*args)
      logger.info(mojo_msg(*args))
    end

    def mojo_warn(*args)
      logger.warn(mojo_msg(*args))
    end

    def mojo_error(*args)
      logger.error(mojo_msg(*args))
    end


    def config
      @@config = MojoLogger::Configurator.new

      yield(@@config) if block_given?

      @@logger = configure_logger
      @@config
    end


  private

    def configure_logger
      @@config ||= MojoLogger::Configurator.new

      stringio = StringIO.new(@@config.generate_properties_string)
      java_stringio = org.jruby.util.IOInputStream.new(stringio)

      Java::org.apache.log4j.PropertyConfigurator.configure(java_stringio)
      Java::org.apache.log4j.Logger.getLogger('MojoLogger')
    end

    def process_options(options=nil)
      case options
      when Hash
        options
      when String
        { 'options' => options }
      else
        nil
      end<commit_msg>Adding ability to call default_log_level on MojoLogger now. Needed to refactor how we access @@config though.<commit_after>require 'java'
require 'time'
require 'json'
require_relative '../jars/log4j-1.2.17.jar'

module MojoLogger

  def mojo_debug(*args)
    MojoLogger.mojo_debug(*args)
  end

  def mojo_info(*args)
    MojoLogger.mojo_info(*args)
  end

  def mojo_warn(*args)
    MojoLogger.mojo_warn(*args)
  end

  def mojo_error(*args)
    MojoLogger.mojo_error(*args)
  end

  def logger
    MojoLogger.logger
  end

  class << self

    def logger
      @@logger ||= configure_logger
    end

    def mojo_msg(api_request, category, message, options=nil)
      msg = {
        'time' => Time.now.utc.strftime("%m-%d-%Y %H:%M:%S.%L %z"),
        'app' => "Mojo",
        'session_id' => api_request[:session_id],
        'reference_id' => api_request[:reference_id],
        'api' => api_request[:api],
        'category' => category,
        'message' => message
      }

      processed_opts = process_options(options)
      msg.merge!(processed_opts) if processed_opts

      msg.to_json
    end

    def mojo_debug(*args)
      logger.debug(mojo_msg(*args))
    end

    def mojo_info(*args)
      logger.info(mojo_msg(*args))
    end

    def mojo_warn(*args)
      logger.warn(mojo_msg(*args))
    end

    def mojo_error(*args)
      logger.error(mojo_msg(*args))
    end

    def default_log_level
      configurator.default_log_level
    end

    def config
      if block_given?
        @@config = MojoLogger::Configurator.new
        yield(@@config)
        @@logger = configure_logger
      end

      configurator
    end


    private

    def configurator
      @@config ||= MojoLogger::Configurator.new
    end

    def configure_logger
      stringio = StringIO.new(configurator.generate_properties_string)
      java_stringio = org.jruby.util.IOInputStream.new(stringio)

      Java::org.apache.log4j.PropertyConfigurator.configure(java_stringio)
      Java::org.apache.log4j.Logger.getLogger('MojoLogger')
    end

    def process_options(options=nil)
      case options
      when Hash
        options
      when String
        { 'options' => options }
      else
        nil
      end
{'fraction_non_alphanumeric': 0.11354439419185908, 'fraction_numerical': 0.0033325398714591763, 'mean_word_length': 2.6539130434782607, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, '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': '3926635', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1379, 'n_words': 260}