<commit_before>################################################################################
# EasyAppHelper 
#
# Copyright (c) 2013 L.Briais under MIT license
# http://opensource.org/licenses/MIT
################################################################################

require 'logger'


# This module provides access to logger(Logger) fully configured according to command line options
# or config files.
#
# It will replace the stupid EasyAppHelper::Common::DummyLogger if the
# module is included.
#
# It brings as well some command line options to manipulate debug.
# See --help
module EasyAppHelper::Logger

  # This module has the highest priority in order to be processed the first by
  # the framework and therefore give a chance to other modules to use it to log.
  MODULE_PRIORITY = 1

  include EasyAppHelper::Common


  # Returns the current log_level.
  def log_level
    app_config[:"log-level"]
  end

  # Enables to hot-change the log level.
  def log_level=(level)
    app_config[:"log-level"] = level
    logger.level = level
  end


  # Build logger for the application. Depending on config may end-up up to nowhere 
  # (by default), STDOUT, STDERR or a file. See --help or EasyAppHelper::Config#help
  # for all options.
  def build_logger
    @logger = EasyAppHelper::Common::DummyLogger.instance
    issue_report = nil
    if app_config[:debug]
      unless app_config[:"log-file"].nil?
        begin
          if File.exists? app_config[:"log-file"]
            logger_type = File.open(app_config[:"log-file"], File::WRONLY | File::APPEND)
          else
            logger_type = File.open(app_config[:"log-file"], File::WRONLY | File::CREAT)
          end
        rescue Exception => e
          logger_type = STDOUT
          issue_report = e.message
        end
      else
        logger_type =  STDOUT
      end
      logger_type = STDERR if app_config[:"debug-on-err"]
      @logger = Logger.new(logger_type)
    end
    app_config[:'log-level'] = DEFAULT_LOG_LEVEL if app_config[:'log-level'].nil?
    logger.level = app_config[:"log-level"]
    logger.error issue_report if issue_report
    logger.debug "Logger is created."
  end


end


module EasyAppHelper::Logger::Instanciator
  extend EasyAppHelper::Common::Instanciator

  # Default module priority
  MODULE_PRIORITY = 1

  # Adds some command line options for this module.
  # - +--debug+
  # - +--debug-on-err+ to have the debugging going to STDERR. Should be used on top of 
  #   --debug.
  # - +--log-file+ +filename+ To log to a specific file. 
  # - +--log-level+ +0-5+ Log level according to Logger::Severity
  def self.add_cmd_line_options(app, slop_definition)
    slop_definition.separator "\n-- Debug and logging options ---------------------------------"
    slop_definition.on :debug, 'Run in debug mode.', :argument => false
    slop_definition.on 'debug-on-err', 'Run in debug mode with output to stderr.', :argument => false
    slop_definition.on 'log-level', "Log level from 0 to 5, default #{EasyAppHelper::Common::DEFAULT_LOG_LEVEL}.", :argument => true, :as => Integer
    slop_definition.on 'log-file', 'File to log to.', :argument => true
  end

  # Creates the application logger
  def self.post_config_action(app)
    app.build_logger<commit_msg>Modified Logger module Remove builder from the helper as useless for the app. Added puts_and_logs<commit_after>################################################################################
# EasyAppHelper 
#
# Copyright (c) 2013 L.Briais under MIT license
# http://opensource.org/licenses/MIT
################################################################################

require 'logger'


# This module provides access to logger(Logger) fully configured according to command line options
# or config files.
#
# It will replace the stupid EasyAppHelper::Common::DummyLogger if the
# module is included.
#
# It brings as well some command line options to manipulate debug.
# See --help
module EasyAppHelper::Logger

  # This module has the highest priority in order to be processed the first by
  # the framework and therefore give a chance to other modules to use it to log.
  MODULE_PRIORITY = 1

  include EasyAppHelper::Common


  # Returns the current log_level.
  def log_level
    app_config[:"log-level"]
  end

  # Enables to hot-change the log level.
  def log_level=(level)
    app_config[:"log-level"] = level
    logger.level = level
  end

  def logger=(logger)
    @logger = logger
  end

  # Displays the message according to application verbosity and logs it as info.
  def puts_and_logs(msg)
    puts msg if app_config[:verbose]
    logger.info(msg)
  end


end


module EasyAppHelper::Logger::Instanciator
  extend EasyAppHelper::Common::Instanciator

  # Default module priority
  MODULE_PRIORITY = 1

  # Adds some command line options for this module.
  # - +--debug+
  # - +--debug-on-err+ to have the debugging going to STDERR. Should be used on top of 
  #   --debug.
  # - +--log-file+ +filename+ To log to a specific file. 
  # - +--log-level+ +0-5+ Log level according to Logger::Severity
  def self.add_cmd_line_options(app, slop_definition)
    slop_definition.separator "\n-- Debug and logging options ---------------------------------"
    slop_definition.on :debug, 'Run in debug mode.', :argument => false
    slop_definition.on 'debug-on-err', 'Run in debug mode with output to stderr.', :argument => false
    slop_definition.on 'log-level', "Log level from 0 to 5, default #{EasyAppHelper::Common::DEFAULT_LOG_LEVEL}.", :argument => true, :as => Integer
    slop_definition.on 'log-file', 'File to log to.', :argument => true
  end

  # Creates the application logger
  def self.post_config_action(app)
  # Build logger for the application. Depending on config may end-up up to nowhere 
  # (by default), STDOUT, STDERR or a file. See --help or EasyAppHelper::Config#help
  # for all options.
    @logger = EasyAppHelper::Common::DummyLogger.instance
    issue_report = nil
    if app.app_config[:debug]
      unless app.app_config[:"log-file"].nil?
        begin
          if File.exists? app.app_config[:"log-file"]
            logger_type = File.open(app.app_config[:"log-file"], File::WRONLY | File::APPEND)
          else
            logger_type = File.open(app.app_config[:"log-file"], File::WRONLY | File::CREAT)
          end
        rescue Exception => e
          logger_type = STDOUT
          issue_report = e.message
        end
      else
        logger_type =  STDOUT
      end
      logger_type = STDERR if app.app_config[:"debug-on-err"]
      app.logger = Logger.new(logger_type)
    end
    app.app_config[:'log-level'] = EasyAppHelper::Common::DEFAULT_LOG_LEVEL if app.app_config[:'log-level'].nil?
    app.logger.level = app.app_config[:"log-level"]
    app.logger.error issue_report if issue_report
    app.logger.debug "Logger is created."
{'fraction_non_alphanumeric': 0.15278383485971797, 'fraction_numerical': 0.0029073993312981536, 'mean_word_length': 3.3352236925015752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '6318372', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1962, 'n_words': 636}