""" Author: md """ import logging import sys def build_logger( logger_name: str, level: int, log_file: str = None, log_mode: str = "a", formatter: str = "%(asctime)s | [%(name)s] | %(levelname)s | %(message)s", ): logger = logging.getLogger(logger_name) logger.setLevel(level) logger.handlers.clear() formatter = logging.Formatter(formatter) if log_file is not None: handler = logging.FileHandler(log_file, log_mode) else: handler = logging.StreamHandler(sys.stdout) handler.setFormatter(formatter) logger.addHandler(handler) return logger