<commit_before># coding: utf-8

import logging
from logging.handlers import RotatingFileHandler
import os
import os.path
from publicstatic import conf
from publicstatic import const
from publicstatic import helpers

_logger = None


def logger():
    global _logger
    if _logger is None:
        _logger = get_logger()
    return _logger


def get_logger():
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    def add_channel(channel):
        level = logging.DEBUG if conf.get('verbose', False) else logging.INFO
        formatter = logging.Formatter(const.LOG_FORMAT, const.LOG_DATE_FORMAT)
        channel.setLevel(level)
        channel.setFormatter(formatter)
        logger.addHandler(channel)

    add_channel(logging.StreamHandler())

    log_file = conf.get('log_file')
    if log_file is not None:
        helpers.makedirs(os.path.dirname(log_file))
        backup_cnt = conf.get('log_backup_cnt', 0)
        max_bytes = conf.get('log_max_size', 0)
        add_channel(RotatingFileHandler(log_file,
                                        maxBytes=max_bytes,
                                        backupCount=backup_cnt))
    return logger


def debug(message):
    logger().debug(message)


def info(message):
    logger().info(message)


def warn(message):
    logger().warn(message)


def error(message):
    logger().error(message)


def fatal(message):
    logger().fatal(message)


def crash():
    """Crash report."""
    import traceback
    import sys
    from datetime import datetime
    message = sys.exc_info()[1]
    with open(const.DUMP_FILE, 'w') as f:
        report = "{generator}, {time}\n\n{message}"
        timestamp = datetime.now().strftime(const.LOG_DATE_FORMAT)
        f.write(report.format(generator=const.GENERATOR,
                              time=timestamp,
                              message=traceback.format_exc()))
    exit("error: %s\nsee %s for details" % (message, const.DUMP_FILE))<commit_msg>Custom crash logging idea considered heretical. Crash logging will use logging.critical().<commit_after># coding: utf-8

import logging
from logging.handlers import RotatingFileHandler
import os
import os.path
from publicstatic import conf
from publicstatic import const
from publicstatic import helpers

_logger = None


def logger():
    global _logger
    if _logger is None:
        _logger = get_logger()
    return _logger


def get_logger():
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)

    def add_channel(channel):
        level = logging.DEBUG if conf.get('verbose', False) else logging.INFO
        formatter = logging.Formatter(const.LOG_FORMAT, const.LOG_DATE_FORMAT)
        channel.setLevel(level)
        channel.setFormatter(formatter)
        logger.addHandler(channel)

    add_channel(logging.StreamHandler())

    log_file = conf.get('log_file')
    if log_file is not None:
        helpers.makedirs(os.path.dirname(log_file))
        backup_cnt = conf.get('log_backup_cnt', 0)
        max_bytes = conf.get('log_max_size', 0)
        add_channel(RotatingFileHandler(log_file,
                                        maxBytes=max_bytes,
                                        backupCount=backup_cnt))
    return logger


def debug(message):
    logger().debug(message)


def info(message):
    logger().info(message)


def warn(message):
    logger().warn(message)


def error(message):
    logger().error(message)


def fatal(message):
    logger().fatal(message)


def crash():
    """Crash report."""
    import traceback
    logging.critical(traceback.format_exc())
{'fraction_non_alphanumeric': 0.10153417015341702, 'fraction_numerical': 0.0019525801952580196, 'mean_word_length': 2.8230277185501067, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4702056', 'n_tokens_mistral': 1036, 'n_tokens_neox': 1000, 'n_words': 238}