<commit_before>"""
Logger
------

This module contains pywincffi's logger and provides functions to
configure the logger at runtime.
"""

import logging

from pywincffi.core.config import config

try:
    NullHandler = logging.NullHandler

except AttributeError:  # pragma: no cover
    # Python 2.6 does not have a NullHandler
    class NullHandler(logging.Handler):
        """
        A Python 2.6 implementation of Python 2.7's
        :class:`logging.NullHandler`
        """
        def handle(self, record):
            pass

        def emit(self, record):
            pass

        def createLock(self):
            self.lock = None

HANDLER = logging.StreamHandler()
HANDLER.setFormatter(
    logging.Formatter(
        "%(asctime)s %(name)s %(levelname)9s %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S"
    )
)

logger = logging.getLogger("pywincffi")
logger.addHandler(NullHandler())


def get_logger(name):
    """
    Returns an instance of :class:`logging.Logger` as a child of
    pywincffi's main logger.

    :param str name:
        The name of the child logger to return. For example,
        if you provide `foo` for the name the resulting name
        will be `pywincffi.foo`.

    :raises ValueError:
        Raised if ``name`` starts with a dot.

    :rtype: :class:`logging.Logger`
    """
    if name.startswith("."):
        raise ValueError("`name` cannot start with '.'")

    try:
        child_logger = logger.getChild(name)

    # getChild was introduced in Python 2.6
    except AttributeError:
        child_logger = logging.getLogger(logger.name + "." + name)

    configured_level = config.logging_level()

    # Root logging configuration has changed, reconfigure.
    if logger.level != configured_level:
        if configured_level == logging.NOTSET:
            logger.handles[:] = []  # pylint: disable=no-member
            logger.setLevel(configured_level)
            logger.addHandler(NullHandler())

        else:
            if HANDLER not in logger.handlers:
                logger.addHandler(HANDLER)

        logger.setLevel(configured_level)

    return child_logger<commit_msg>rename HANDLER -> STREAM_HANDLER to better represent the class<commit_after>"""
Logger
------

This module contains pywincffi's logger and provides functions to
configure the logger at runtime.
"""

import logging

from pywincffi.core.config import config

try:
    NullHandler = logging.NullHandler

except AttributeError:  # pragma: no cover
    # Python 2.6 does not have a NullHandler
    class NullHandler(logging.Handler):
        """
        A Python 2.6 implementation of Python 2.7's
        :class:`logging.NullHandler`
        """
        def handle(self, record):
            pass

        def emit(self, record):
            pass

        def createLock(self):
            self.lock = None

FORMATTER = logging.Formatter(
    "%(asctime)s %(name)s %(levelname)9s %(message)s",
    datefmt="%Y-%m-%d %H:%M:%S")
STREAM_HANDLER = logging.StreamHandler()
STREAM_HANDLER.setFormatter(FORMATTER)

logger = logging.getLogger("pywincffi")
logger.addHandler(NullHandler())


def get_logger(name):
    """
    Returns an instance of :class:`logging.Logger` as a child of
    pywincffi's main logger.

    :param str name:
        The name of the child logger to return. For example,
        if you provide `foo` for the name the resulting name
        will be `pywincffi.foo`.

    :raises ValueError:
        Raised if ``name`` starts with a dot.

    :rtype: :class:`logging.Logger`
    """
    if name.startswith("."):
        raise ValueError("`name` cannot start with '.'")

    try:
        child_logger = logger.getChild(name)

    # getChild was introduced in Python 2.6
    except AttributeError:
        child_logger = logging.getLogger(logger.name + "." + name)

    configured_level = config.logging_level()

    # Root logging configuration has changed, reconfigure.
    if logger.level != configured_level:
        if configured_level == logging.NOTSET:
            logger.handles[:] = []  # pylint: disable=no-member
            logger.setLevel(configured_level)
            logger.addHandler(NullHandler())

        else:
            if STREAM_HANDLER not in logger.handlers:
                logger.addHandler(STREAM_HANDLER)

        logger.setLevel(configured_level)

    return child_logger
{'fraction_non_alphanumeric': 0.10382136279926335, 'fraction_numerical': 0.004143646408839779, 'mean_word_length': 2.614808652246256, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '779772', 'n_tokens_mistral': 1297, 'n_tokens_neox': 1253, 'n_words': 355}