async_logger.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. from .levels import levels
  2. from .handler import handler
  3. from .logger import logger
  4. class async_logger(logger):
  5. """
  6. That is logger, which use async methods to save data into handles.
  7. Methods
  8. -------
  9. async info(content, *args, **kwargs)
  10. That log info level message.
  11. async warning(content, *args, **kwargs)
  12. That log warning level message.
  13. async error(content, *args, **kwargs)
  14. That log error level message.
  15. async critical(content, *args, **kwargs)
  16. That log critical level message.
  17. async log(level, content, *args, **kwargs)
  18. That generally save content to log with given level.
  19. """
  20. async def info(self, content: str, *args, **kwargs) -> None:
  21. """
  22. That log info level message.
  23. Parameters
  24. ----------
  25. content : str
  26. Content to store in the log.
  27. *args, **kwargs
  28. When any of that parameters had been given, then format funcion
  29. hed been used on the content.
  30. """
  31. await self.log(levels.info, content, *args, **kwargs)
  32. async def warning(self, content: str, *args, **kwargs) -> None:
  33. """
  34. That log info level message.
  35. Parameters
  36. ----------
  37. content : str
  38. Content to store in the log.
  39. *args, **kwargs
  40. When any of that parameters had been given, then format funcion
  41. hed been used on the content.
  42. """
  43. await self.log(levels.warning, content, *args, **kwargs)
  44. async def error(self, content: str, *args, **kwargs) -> None:
  45. await self.log(levels.error, content, *args, **kwargs)
  46. async def critical(self, content: str, *args, **kwargs) -> None:
  47. await self.log(levels.critical, content, *args, **kwargs)
  48. async def log(self, level: levels, content: str, *args, **kwargs) -> None:
  49. await self._write_to_all(
  50. self._get_message(level, content, *args, **kwargs)
  51. )
  52. async def _write_to_all(self, content: str) -> None:
  53. for handler in self._get_handlers():
  54. await handler.adding(content)