<commit_before>"""
This is  a critical component but it causes circular dependencies
because everything needs it, so we abstract it in its own class
"""

import os
import sys
import logging
from .formatting import Colors, ColorNotFoundError
from datetime import datetime
from PyFBA import __version__

logger = None


def initiate_logger(logname=f"PyFBA.{datetime.now().isoformat()}.log"):
    # define a logger
    global logger
    logger = logging.getLogger('PyFBA')
    logger.setLevel(5)
    loglocation = os.path.join(os.getcwd(), logname)
    sys.stderr.write(f"We are logging to {loglocation}\n")
    hdlr = logging.FileHandler(loglocation)
    fmt = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
    hdlr.setFormatter(fmt)
    logger.addHandler(hdlr)

    logging.getLogger('PyFBA').info(f"Welcome to PyFBA version {__version__} started at {datetime.now()}")


def message(msg, c, stream):
    """
    Print a message to stderr using color
    :param msg: the message to print
    :param c: the colour to use
    :param stream: either stderr or stdout
    :return: nothing
    """

    c = c.upper()
    # we strip any newline off message in case it was added and then we add it here! Ensures always only one newline
    msg = msg.strip()
    if c not in Colors.color:
        raise ColorNotFoundError(f"Color {c} was not found")
<commit_msg>Putting the logs in `logs/`<commit_after>"""
This is  a critical component but it causes circular dependencies
because everything needs it, so we abstract it in its own class
"""

import os
import sys
import logging
from .formatting import Colors, ColorNotFoundError
from datetime import datetime
from PyFBA import __version__

logger = None


def initiate_logger(logname=f"PyFBA.{datetime.now().isoformat()}.log", logdir=None):
    """
    Instantiate a logger, and write outputs to the log.

    If logdir is not defined, we use os.getcwd()/logs/ to store the logs. Otherwise, provide a pathh to the location
    :param logname: the name of the file to save the logs to
    :param logdir:  the directory to write the logs to
    :return: the instantiated logger.
    """
    global logger
    logger = logging.getLogger('PyFBA')
    logger.setLevel(5)
    if not logdir:
        logdir = os.path.join(os.getcwd(), 'logs')
    os.makedirs(logdir, exist_ok=True)

    loglocation = os.path.join(logdir, logname)
    sys.stderr.write(f"We are logging to {loglocation}\n")
    hdlr = logging.FileHandler(loglocation)
    fmt = logging.Formatter('%(asctime)s %(levelname)-8s %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
    hdlr.setFormatter(fmt)
    logger.addHandler(hdlr)

    logging.getLogger('PyFBA').info(f"Welcome to PyFBA version {__version__} started at {datetime.now()}")


def message(msg, c, stream):
    """
    Print a message to stderr using color
    :param msg: the message to print
    :param c: the colour to use
    :param stream: either stderr or stdout
    :return: nothing
    """

    c = c.upper()
    # we strip any newline off message in case it was added and then we add it here! Ensures always only one newline
    msg = msg.strip()
    if c not in Colors.color:
        raise ColorNotFoundError(f"Color {c} was not found")

{'fraction_non_alphanumeric': 0.10573366214549938, 'fraction_numerical': 0.0012330456226880395, 'mean_word_length': 3.6291012838801713, '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': '2095441', 'n_tokens_mistral': 1021, 'n_tokens_neox': 1006, 'n_words': 359}