<commit_before>"""Provides a multiprocessing-safe logger with colored console output,
rotating log files, and easy block-timing based on the logging module.

Logging made easy. Just use the module level functions debug, warning,
info etc. to log messages. At some point, preferably at the start of
your program, call init_main to initialize the logger and choose at
which level you want to log to the console and or rotating log files.

Timing made easy. Just use the module level function timed in a 'with'
block to log timing of the code in the block. You can also get a
summary with statistics of all your timed blocks by calling
print_timings.

Written by <NAME>, inspired by zzzeek's and airmind's examples on
Stackoverflow (http://stackoverflow.com/a/894284/2481888,
http://stackoverflow.com/a/384125/2481888).

"""
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import

import logging
import logging.handlers
import copy

import os
import numpy as np

from collections import OrderedDict
from datetime import datetime
from contextlib import contextmanager

from pyexperiment.utils.Singleton import Singleton
from pyexperiment.utils.Singleton import InitializeableSingleton
from pyexperiment.utils.DelegateCall import DelegateCall

from pyexperiment.utils import printers


CONSOLE_FORMAT = ("[%(levelname)-19s] [%(relativeCreated)s]"
                  " $BOLD%(message)s$RESET")
"""The format used for logging to the console
"""  # pylint:disable=W0105

FILE_FORMAT_STD_MSG_LEN = 50
"""How much space should be reserved for a normal message in the log
file.
"""  # pylint:disable=W0105

FILE_FORMAT = ("[%(relativeCreated)0.5fs] [%(levelname)-1s]"
               " %(message)-50s (%(filename)s:%(lineno)d) %(processName)s "
               "- %(threadName)s")
"""The format used for logging to file
"""  # pylint:disable=W0105

CONSOLE_STREAM_HANDLER = logging.StreamHandler()
"""The stream handler for the console (can be mocked for testing)
"""  # pylint:disable=W0105


class ColorFormatter(logging.Formatter):
    """Formats logged messages with optional added color for the log level
    """
    def __init__(self, msg, use_color=True):
        """Initializer
        """
        super(ColorFormatter, self).__init__(msg)
        self.use_color = use_color
        self.log_no = 0
        self.colors = self._setup_log_level_colors()

    @staticmethod
    def _setup_log_level_colors():
        """Returns a dictionary with the colors associated to each log level.
        """
        return {'WARNING': printers.MAGENTA,
                'INFO': printers.WHITE,
                'DEBUG': printers.BLUE,
                'CRITICAL': printers.YELLOW,
                'ERROR': printers.RED}
<commit_msg>Fix log file time format.<commit_after>"""Provides a multiprocessing-safe logger with colored console output,
rotating log files, and easy block-timing based on the logging module.

Logging made easy. Just use the module level functions debug, warning,
info etc. to log messages. At some point, preferably at the start of
your program, call init_main to initialize the logger and choose at
which level you want to log to the console and or rotating log files.

Timing made easy. Just use the module level function timed in a 'with'
block to log timing of the code in the block. You can also get a
summary with statistics of all your timed blocks by calling
print_timings.

Written by <NAME>, inspired by zzzeek's and airmind's examples on
Stackoverflow (http://stackoverflow.com/a/894284/2481888,
http://stackoverflow.com/a/384125/2481888).

"""
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import

import logging
import logging.handlers
import copy

import os
import numpy as np

from collections import OrderedDict
from datetime import datetime
from contextlib import contextmanager

from pyexperiment.utils.Singleton import Singleton
from pyexperiment.utils.Singleton import InitializeableSingleton
from pyexperiment.utils.DelegateCall import DelegateCall

from pyexperiment.utils import printers


CONSOLE_FORMAT = ("[%(levelname)-19s] [%(relativeCreated)s]"
                  " $BOLD%(message)s$RESET")
"""The format used for logging to the console
"""  # pylint:disable=W0105

FILE_FORMAT_STD_MSG_LEN = 50
"""How much space should be reserved for a normal message in the log
file.
"""  # pylint:disable=W0105

FILE_FORMAT = ("[%(relativeCreated)10.5fs] [%(levelname)-1s]"
               " %(message)-50s (%(filename)s:%(lineno)d) %(processName)s "
               "- %(threadName)s")
"""The format used for logging to file
"""  # pylint:disable=W0105

CONSOLE_STREAM_HANDLER = logging.StreamHandler()
"""The stream handler for the console (can be mocked for testing)
"""  # pylint:disable=W0105


class ColorFormatter(logging.Formatter):
    """Formats logged messages with optional added color for the log level
    """
    def __init__(self, msg, use_color=True):
        """Initializer
        """
        super(ColorFormatter, self).__init__(msg)
        self.use_color = use_color
        self.log_no = 0
        self.colors = self._setup_log_level_colors()

    @staticmethod
    def _setup_log_level_colors():
        """Returns a dictionary with the colors associated to each log level.
        """
        return {'WARNING': printers.MAGENTA,
                'INFO': printers.WHITE,
                'DEBUG': printers.BLUE,
                'CRITICAL': printers.YELLOW,
                'ERROR': printers.RED}

{'fraction_non_alphanumeric': 0.08554152587586697, 'fraction_numerical': 0.018673306064378444, 'mean_word_length': 3.79045996592845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '3477533', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1544, 'n_words': 576}