2022-05-14 09:43:02 +00:00
|
|
|
from typing import Any, Callable
|
2022-05-10 20:23:12 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger("discord-rich-presence-plex")
|
|
|
|
logger.setLevel(logging.INFO)
|
2022-05-22 04:37:09 +00:00
|
|
|
formatter = logging.Formatter("[%(asctime)s] [%(levelname)s] %(message)s", datefmt = "%d-%m-%Y %I:%M:%S %p")
|
|
|
|
streamHandler = logging.StreamHandler()
|
|
|
|
streamHandler.setFormatter(formatter)
|
|
|
|
logger.addHandler(streamHandler)
|
2022-05-10 20:23:12 +00:00
|
|
|
|
|
|
|
class LoggerWithPrefix:
|
|
|
|
|
|
|
|
def __init__(self, prefix: str) -> None:
|
|
|
|
self.prefix = prefix
|
2022-05-22 04:37:09 +00:00
|
|
|
self.info = self.wrapLoggerFunc(logger.info)
|
|
|
|
self.warning = self.wrapLoggerFunc(logger.warning)
|
|
|
|
self.error = self.wrapLoggerFunc(logger.error)
|
|
|
|
self.exception = self.wrapLoggerFunc(logger.exception)
|
|
|
|
self.debug = self.wrapLoggerFunc(logger.debug)
|
2022-05-14 09:43:02 +00:00
|
|
|
|
2022-05-22 04:37:09 +00:00
|
|
|
def wrapLoggerFunc(self, func: Callable[..., None]) -> Callable[..., None]:
|
2022-05-14 09:43:02 +00:00
|
|
|
def wrappedFunc(obj: Any, *args: Any, **kwargs: Any) -> None:
|
|
|
|
func(self.prefix + str(obj), *args, **kwargs)
|
|
|
|
return wrappedFunc
|