<commit_before>import logging

# This module is redundantly called pubres_logging
# to not conflict with the stdlib logging module.


# The official logger name of pubres.
PUBRES_LOGGER_NAME = 'pubres'


def setup_logging(level):
    # Check if the log level string is one defined in logging
    numeric_level = getattr(logging, level.upper())
    if not isinstance(numeric_level, int):
        raise ValueError('Invalid log level: %s' % level)

    ## Logger, handler and formatter

    logger = logging.getLogger(PUBRES_LOGGER_NAME)
    logger.setLevel(numeric_level)

    handler = logging.StreamHandler()
    handler.setLevel(numeric_level)

    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)

    logger.addHandler(handler)
<commit_msg>pubres_logging: Cllow custom log level and handler<commit_after>import logging

# This module is redundantly called pubres_logging
# to not conflict with the stdlib logging module.


# The official logger name of pubres.
PUBRES_LOGGER_NAME = 'pubres'


def setup_logging(level=logging.INFO, handler=None):
    """Configures a logger called 'pubres'.

    Optionally takes:
    - a log level (either a string like 'INFO' or numeric constant like logging.INFO)
    - a custom log handler to process the `LogRecords`.
    """
    # Check if the log level string is one defined in logging
    numeric_level = getattr(logging, level.upper()) if isinstance(level, str) else level
    if not isinstance(numeric_level, int):
        raise ValueError('Invalid log level: %s' % level)

    ## Logger, handler and formatter

    logger = logging.getLogger(PUBRES_LOGGER_NAME)
    logger.setLevel(numeric_level)

    if handler is None:
        handler = logging.StreamHandler()
        handler.setLevel(numeric_level)

    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(formatter)

    logger.addHandler(handler)

{'fraction_non_alphanumeric': 0.09233097880928355, 'fraction_numerical': 0.0, 'mean_word_length': 3.969924812030075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1172003', 'n_tokens_mistral': 593, 'n_tokens_neox': 571, 'n_words': 178}