<commit_before># -*- coding: utf-8 -*-

"""
Command-line interface helper
"""

# This code is a part of chirptext library: https://github.com/letuananh/chirptext
# :copyright: (c) 2012 <NAME> <<EMAIL>>
# :license: MIT, see LICENSE for more details.

import os
import logging
import logging.config
import argparse
import json


# -------------------------------------------------------------------------------
# Configuration
# -------------------------------------------------------------------------------

class ChirpCLI(object):
    SETUP_COMPLETED = False


def getLogger():
    return logging.getLogger(__name__)


# -------------------------------------------------------------------------------
# Application logic
# -------------------------------------------------------------------------------

def setup_logging(filename, log_dir=None, force_setup=False):
    """ Try to load logging configuration from a file. Set level to INFO if failed.
    """
    if not force_setup and ChirpCLI.SETUP_COMPLETED:
        logging.debug("Master logging has been setup. This call will be ignored.")
        return
    if log_dir and not os.path.exists(log_dir):
        os.makedirs(log_dir)
    if os.path.isfile(filename):
        with open(filename) as config_file:
            try:
                config = json.load(config_file)
                logging.config.dictConfig(config)
                logging.info("logging was setup using {}".format(filename))
                ChirpCLI.SETUP_COMPLETED = True
            except Exception as e:
                logging.exception("Could not load logging config")
                # default logging config
                logging.basicConfig(level=logging.INFO)
    else:
        logging.basicConfig(level=logging.INFO)


def config_logging(args):
    """ Override root logger's level """
    if args.quiet:
        logging.getLogger().setLevel(logging.CRITICAL)
    elif args.verbose:
        logging.getLogger().setLevel(logging.DEBUG)


class CLIApp(object):
    """ A simple template for command-line interface applications """

    def __init__(self, desc, add_vq=True, add_tasks=True, **kwargs):
        """
        Init an app instance
        """
        self.__parser = argparse.ArgumentParser(description=desc, add_help=False)<commit_msg>less aggressive logging by default<commit_after># -*- coding: utf-8 -*-

"""
Command-line interface helper
"""

# This code is a part of chirptext library: https://github.com/letuananh/chirptext
# :copyright: (c) 2012 <NAME> <<EMAIL>>
# :license: MIT, see LICENSE for more details.

import os
import logging
import logging.config
import argparse
import json


# -------------------------------------------------------------------------------
# Configuration
# -------------------------------------------------------------------------------

class ChirpCLI(object):
    SETUP_COMPLETED = False


def getLogger():
    return logging.getLogger(__name__)


# -------------------------------------------------------------------------------
# Application logic
# -------------------------------------------------------------------------------

def setup_logging(config_path, log_dir=None, force_setup=False, default_level= logging.WARNING, silent=True):
    """ Try to load logging configuration from a file. Set level to INFO if failed.

    :param config_path: Path to the logging config file (JSON)
    :param log_dir: Path to log output directory. When log_dir is not None and the directory does not exist, it will be created automatically.
    """
    if not force_setup and ChirpCLI.SETUP_COMPLETED:
        if not silent:
            logging.debug("Master logging has been setup. This call will be ignored.")
        return
    if log_dir and not os.path.exists(log_dir):
        try:
            os.makedirs(log_dir)
        except OSError:
            if not silent:
                logging.exception("Could not create logging folder")
    if os.path.isfile(config_path):
        with open(config_path) as config_file:
            try:
                config = json.load(config_file)
                logging.config.dictConfig(config)
                if not silent:
                    logging.info("logging was setup using {}".format(config_path))
                ChirpCLI.SETUP_COMPLETED = True
            except Exception:
                if not silent:
                    logging.exception("Could not load logging config")
                # default logging config
                logging.basicConfig(level=default_level)
    else:
        logging.basicConfig(level=default_level)


def config_logging(args):
    """ Override root logger's level """
    if args.quiet:
        logging.getLogger().setLevel(logging.CRITICAL)
    elif args.verbose:
        logging.getLogger().setLevel(logging.DEBUG)


class CLIApp(object):
    """ A simple template for command-line interface applications """

    def __init__(self, desc, add_vq=True, add_tasks=True, **kwargs):
        """
        Init an app instance
        """
        self.__parser = argparse.ArgumentParser(description=desc, add_help=False)
{'fraction_non_alphanumeric': 0.20797329143754908, 'fraction_numerical': 0.0019638648860958365, 'mean_word_length': 1.7604336043360433, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2046289', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1243, 'n_words': 364}