<commit_before># encoding: utf-8

"""
.. codeauthor:: <NAME> <<EMAIL>>
"""

from __future__ import absolute_import
from __future__ import unicode_literals

import dataproperty
import logbook
from mbstrdecoder import MultiByteStrDecoder
import pytablereader
import simplesqlite


logger = logbook.Logger("pytablewriter")
logger.disable()


def set_logger(is_enable):
    dataproperty.set_logger(is_enable)
    pytablereader.set_logger(is_enable)
    simplesqlite.set_logger(is_enable)

    if is_enable:
        logger.enable()
    else:
        logger.disable()


def set_log_level(log_level):
    """
    Set logging level of this module. Using
    `logbook <http://logbook.readthedocs.io/en/stable/>`__ module for logging.

    :param int log_level:
        One of the log level of
        `logbook <http://logbook.readthedocs.io/en/stable/api/base.html>`__.
        Disabled logging if ``log_level`` is ``logbook.NOTSET``.
    """

    dataproperty.set_log_level(log_level)
    pytablereader.set_log_level(log_level)
    simplesqlite.set_log_level(log_level)

    if log_level == logbook.NOTSET:
        set_logger(is_enable=False)
    else:
        set_logger(is_enable=True)
        logger.level = log_level


class WriterLogger(object):

    def __init__(self, writer):
        self.__writer = writer
        logger.debug(
            "created WriterLogger: format={}".format(writer.format_name))

    def logging_write(self, extra_message_list=None):
        log_entry_list = self.__get_log_entry_base()

        try:
            log_entry_list.append(
                "rows={}".format(len(self.__writer.value_matrix)))
        except (TypeError, AttributeError):
            pass

        log_entry_list.append(self.__get_typehint_log_message())

        if extra_message_list:
            log_entry_list.extend(extra_message_list)<commit_msg>Modify to avoid excessive logger initialization<commit_after># encoding: utf-8

"""
.. codeauthor:: <NAME> <<EMAIL>>
"""

from __future__ import absolute_import
from __future__ import unicode_literals

import dataproperty
import logbook
from mbstrdecoder import MultiByteStrDecoder
import pytablereader
import simplesqlite


logger = logbook.Logger("pytablewriter")
logger.disable()


def set_logger(is_enable):
    if is_enable != logger.disabled:
        return

    if is_enable:
        logger.enable()
    else:
        logger.disable()

    dataproperty.set_logger(is_enable)
    pytablereader.set_logger(is_enable)
    simplesqlite.set_logger(is_enable)


def set_log_level(log_level):
    """
    Set logging level of this module. Using
    `logbook <http://logbook.readthedocs.io/en/stable/>`__ module for logging.

    :param int log_level:
        One of the log level of
        `logbook <http://logbook.readthedocs.io/en/stable/api/base.html>`__.
        Disabled logging if ``log_level`` is ``logbook.NOTSET``.
    """

    if log_level == logger.level:
        return

    if log_level == logbook.NOTSET:
        set_logger(is_enable=False)
    else:
        set_logger(is_enable=True)
        logger.level = log_level

    dataproperty.set_log_level(log_level)
    pytablereader.set_log_level(log_level)
    simplesqlite.set_log_level(log_level)


class WriterLogger(object):

    def __init__(self, writer):
        self.__writer = writer
        logger.debug(
            "created WriterLogger: format={}".format(writer.format_name))

    def logging_write(self, extra_message_list=None):
        log_entry_list = self.__get_log_entry_base()

        try:
            log_entry_list.append(
                "rows={}".format(len(self.__writer.value_matrix)))
        except (TypeError, AttributeError):
            pass

        log_entry_list.append(self.__get_typehint_log_message())

        if extra_message_list:
            log_entry_list.extend(extra_message_list)
{'fraction_non_alphanumeric': 0.09794217244073977, 'fraction_numerical': 0.0005209690023443605, 'mean_word_length': 3.183006535947712, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '85249', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1197, 'n_words': 228}