from .handler import handler class logger: def __init__(self) -> None: self.__handlers = set() def _get_message(self, *args, **kwargs) -> str: if len(kwargs) == 0: return self.__get_message_from_args(self, *args) if len(args) != 1: raise RuntimeError("You must specify output format.") return self.__get_message_from_kwargs(self, args[0], **kwargs) def __get_message_from_args(self, *args) -> str: line = "" for count in args: typed = type(count) if typed is str: line = line + count + " " continue if typed is int or typed is float or typed is bool: line = line + str(count) + " " continue line = line + repr(count) + " " if len(args) > 0: line = line[0:-1] return line def __get_message_from_kwargs(self, formation: str, **kwargs) -> str: return formation.format(**kwargs) def use_handler(self, target: handler) -> None: self.__handlers.add(target)