<commit_before>"""Logger facility"""

from datetime import datetime

class Logger:

    def __init__(self, **kwargs):
        self.facility = {}

        if 'file' in kwargs:
            self.file_ = kwargs['file']
            self.facility['file'] = FileLogger(self.file_)
        else:
            self.file_ = None

        self.facility['console'] = ConsoleLogger()

    def file(self, data):
        """Write to the file

        Falls back to console if file logging facility is unavailable
        """

        if not self.file_:
            # default to console
            facility = self.facility['console']
        else:
            facility = self.facility['file']

        facility.write(data)

    def console(self, data):
        """Write to the console
        """
        self.facility['console'].write(data)

class ConsoleLogger:

    def write(self, data):
        """Write data"""
        timestamp = datetime.now().strftime('%Y%m%d.%H%M%S')
        print "%s %s" % (timestamp, data)

class FileLogger:

    def __init__(self, file_):
        """Constructor

        @param takes a filename
        """
        self.file_ = file(file_, 'a')

    def write(self, data):
        """Write to file"""
        timestamp = datetime.now().strftime('%Y%m%d.%H%M%S')
        self.file_.write("%s %s\n" % (timestamp, data))
<commit_msg>Added colors (bash) to default console logging<commit_after>"""Logger facility"""

from datetime import datetime

DEFAULT_FMT = (("IN", "\033[1;32mIN\033[0m", 1),
               ("OUT", "\033[1;31mOUT\033[0m", 1))

class Logger:

    def __init__(self, **kwargs):
        self.facility = {}

        if 'file' in kwargs:
            self.file_ = kwargs['file']
            self.facility['file'] = FileLogger(self.file_)
        else:
            self.file_ = None

        if 'fmt' in kwargs:
            self.facility['console'] = ConsoleLogger(fmt=kwargs['fmt'])
        else:
            self.facility['console'] = ConsoleLogger()

    def file(self, data):
        """Write to the file

        Falls back to console if file logging facility is unavailable
        """

        if not self.file_:
            # default to console
            facility = self.facility['console']
        else:
            facility = self.facility['file']

        facility.write(data)

    def console(self, data):
        """Write to the console
        """
        self.facility['console'].write(data)

class ConsoleLogger:

    def __init__(self, **kwargs):
        if 'fmt' in kwargs:
            self.fmt = kwargs['fmt']
        else:
            self.fmt = DEFAULT_FMT

    def write(self, data):
        """Write data"""
        if self.fmt:
            for (find, repl, limit) in self.fmt:
                data = data.replace(find, repl, limit)

        timestamp = datetime.now().strftime('%Y%m%d.%H%M%S')
        print "%s %s" % (timestamp, data)

class FileLogger:

    def __init__(self, file_):
        """Constructor

        @param takes a filename
        """
        self.file_ = file(file_, 'a')

    def write(self, data):
        """Write to file"""
        timestamp = datetime.now().strftime('%Y%m%d.%H%M%S')
        self.file_.write("%s %s\n" % (timestamp, data))

{'fraction_non_alphanumeric': 0.14259086672879775, 'fraction_numerical': 0.006834420627524076, 'mean_word_length': 2.032015065913371, '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': '1401356', 'n_tokens_mistral': 979, 'n_tokens_neox': 943, 'n_words': 246}