Module RelayModel.RelayLogging

Expand source code
import logging
from RelayModel.Relay import Relay


def get_logger(log_level, file_name):
    """Creates a logger object with the given log leven and the output file name.

    Note:
        The file_name should be unique to the specific purpose. Otherwise it can

    Args:
        log_level (int): Defines the log level of the Logger. Normally this should be set to the module config log
            level.
        file_name (str): Defines the file the logging informations should be written to.

    Returns:
        logging.Logger: The logger object with the specific log level and filename.
    """
    logger = logging.getLogger(file_name)

    if log_level == logging.DEBUG or log_level == logging.WARNING or log_level == logging.ERROR \
            or log_level == logging.INFO or log_level == logging.CRITICAL:
        logger.setLevel(log_level)

    file_path = "logs/{}.log".format(file_name)

    file_handler = logging.FileHandler(file_path, 'w')

    formatter = logging.Formatter('%(asctime)s:%(levelname)s: %(threadName)s %(message)s')

    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)

    return logger


def relay_list_to_string(relays):
    """Makes a well formed string from a relay list.

    Outputs a string for the given relay list where every relay is shown with its relay id and its connection to.

    Args:
        relays (list): A list of relays that should be converted to a string.

    Returns:
        str: A well formed str of a list full of relays.
    """
    relay_list = list(relays)

    return str(list(map(lambda x: str(x.relay_id) + "->" + str(x.out_relay.out_id) if isinstance(x, Relay) else 'None',
                        relay_list)))

Functions

def get_logger(log_level, file_name)

Creates a logger object with the given log leven and the output file name.

Note

The file_name should be unique to the specific purpose. Otherwise it can

Args

log_level : int
Defines the log level of the Logger. Normally this should be set to the module config log level.
file_name : str
Defines the file the logging informations should be written to.

Returns

logging.Logger
The logger object with the specific log level and filename.
Expand source code
def get_logger(log_level, file_name):
    """Creates a logger object with the given log leven and the output file name.

    Note:
        The file_name should be unique to the specific purpose. Otherwise it can

    Args:
        log_level (int): Defines the log level of the Logger. Normally this should be set to the module config log
            level.
        file_name (str): Defines the file the logging informations should be written to.

    Returns:
        logging.Logger: The logger object with the specific log level and filename.
    """
    logger = logging.getLogger(file_name)

    if log_level == logging.DEBUG or log_level == logging.WARNING or log_level == logging.ERROR \
            or log_level == logging.INFO or log_level == logging.CRITICAL:
        logger.setLevel(log_level)

    file_path = "logs/{}.log".format(file_name)

    file_handler = logging.FileHandler(file_path, 'w')

    formatter = logging.Formatter('%(asctime)s:%(levelname)s: %(threadName)s %(message)s')

    file_handler.setFormatter(formatter)
    logger.addHandler(file_handler)

    return logger
def relay_list_to_string(relays)

Makes a well formed string from a relay list.

Outputs a string for the given relay list where every relay is shown with its relay id and its connection to.

Args

relays : list
A list of relays that should be converted to a string.

Returns

str
A well formed str of a list full of relays.
Expand source code
def relay_list_to_string(relays):
    """Makes a well formed string from a relay list.

    Outputs a string for the given relay list where every relay is shown with its relay id and its connection to.

    Args:
        relays (list): A list of relays that should be converted to a string.

    Returns:
        str: A well formed str of a list full of relays.
    """
    relay_list = list(relays)

    return str(list(map(lambda x: str(x.relay_id) + "->" + str(x.out_relay.out_id) if isinstance(x, Relay) else 'None',
                        relay_list)))