|
@@ -4,14 +4,39 @@ class logger:
|
|
|
def __init__(self) -> None:
|
|
def __init__(self) -> None:
|
|
|
self.__handlers = set()
|
|
self.__handlers = set()
|
|
|
|
|
|
|
|
- def _on_all(self, content: str) -> None:
|
|
|
|
|
- for handler in self.__handlers:
|
|
|
|
|
- handler(content)
|
|
|
|
|
|
|
+ def _get_message(self, *args, **kwargs) -> str:
|
|
|
|
|
+ if len(kwargs) == 0:
|
|
|
|
|
+ return self.__get_message_from_args(self, *args)
|
|
|
|
|
|
|
|
- async def _on_all_async(self, content: str) -> None:
|
|
|
|
|
- for handler in self.__handlers:
|
|
|
|
|
- await handler.add(content)
|
|
|
|
|
|
|
+ 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:
|
|
def use_handler(self, target: handler) -> None:
|
|
|
self.__handlers.add(target)
|
|
self.__handlers.add(target)
|
|
|
|
|
|