import logging


def build_logger(level, user_file_name=None):
    """
    Builds two loggers : a dev one as well as a user one.
    :param level: The desired level of logging for the dev log.
    If is logging.ERROR (default) then the logging is handled on the stream.
    Otherwise, it outputs in the dev_log.log file
    :type level: logging level
    :returns: The two logger objects
    """
    # Creating DEV logger
    dev_formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s")
    if level != logging.ERROR:
        dev_handler = logging.FileHandler("dev_log.log")
    else:
        dev_handler = logging.StreamHandler()
    dev_handler.setFormatter(dev_formatter)

    dev_logger = logging.getLogger("dev_logger")
    dev_logger.setLevel(level)
    dev_logger.addHandler(dev_handler)

    # Creating User logger
    user_formatter = logging.Formatter("%(message)s")

    if user_file_name is not None:
        user_handler = logging.FileHandler(user_file_name)
    else:
        user_handler = logging.StreamHandler()
    user_handler.setFormatter(user_formatter)

    user_logger = logging.getLogger("user_logger")
    user_logger.setLevel(logging.INFO)
    user_logger.addHandler(user_handler)

    return dev_logger, user_logger