Mercurial > libervia-backend
diff sat/core/log.py @ 3911:8289ac1b34f4
plugin XEP-0384: Fully reworked to adjust to the reworked python-omemo:
- support for both (modern) OMEMO under the `urn:xmpp:omemo:2` namespace and (legacy) OMEMO under the `eu.siacs.conversations.axolotl` namespace
- maintains one identity across both versions of OMEMO
- migrates data from the old plugin
- includes more features for protocol stability
- uses SCE for modern OMEMO
- fully type-checked, linted and format-checked
- added type hints to various pieces of backend code used by the plugin
- added stubs for some Twisted APIs used by the plugin under stubs/ (use `export MYPYPATH=stubs/` before running mypy)
- core (xmpp): enabled `send` trigger and made it an asyncPoint
fix 375
author | Syndace <me@syndace.dev> |
---|---|
date | Tue, 23 Aug 2022 21:06:24 +0200 |
parents | 7550ae9cfbac |
children | 760f563b1243 |
line wrap: on
line diff
--- a/sat/core/log.py Thu Sep 22 12:03:12 2022 +0200 +++ b/sat/core/log.py Tue Aug 23 21:06:24 2022 +0200 @@ -21,6 +21,14 @@ # XXX: this module use standard logging module when possible, but as SàT can work in different cases where logging is not the best choice (twisted, pyjamas, etc), it is necessary to have a dedicated module. Additional feature like environment variables and colors are also managed. # TODO: change formatting from "%s" style to "{}" when moved to Python 3 +from typing import TYPE_CHECKING, Any, Optional +from typing_extensions import TypedDict + +if TYPE_CHECKING: + from logging import _ExcInfoType +else: + _ExcInfoType = Any + from sat.core.constants import Const as C from sat.tools.common.ansi import ANSI as A from sat.core import exceptions @@ -37,6 +45,10 @@ pass +class KWArgs(TypedDict): + exc_info: _ExcInfoType + + class Logger: """High level logging class""" fmt = None # format option as given by user (e.g. SAT_LOG_LOGGER) @@ -60,7 +72,7 @@ tb = traceback.format_exc() return message + "\n==== traceback ====\n" + tb - def out(self, message, level=None, **kwargs): + def out(self, message: object, level: Optional[str] = None, **kwargs: KWArgs) -> None: """Actually log the message @param message: formatted message @@ -69,7 +81,7 @@ message = self.addTraceback(message) print(message) - def log(self, level, message, **kwargs): + def log(self, level: str, message: object, **kwargs: KWArgs) -> None: """Print message @param level: one of C.LOG_LEVELS @@ -84,7 +96,7 @@ except Filtered: pass - def format(self, level, message): + def format(self, level: str, message: object) -> object: """Format message according to Logger.fmt @param level: one of C.LOG_LEVELS @@ -117,19 +129,19 @@ else: raise e - def debug(self, msg, **kwargs): + def debug(self, msg: object, **kwargs: KWArgs) -> None: self.log(C.LOG_LVL_DEBUG, msg, **kwargs) - def info(self, msg, **kwargs): + def info(self, msg: object, **kwargs: KWArgs) -> None: self.log(C.LOG_LVL_INFO, msg, **kwargs) - def warning(self, msg, **kwargs): + def warning(self, msg: object, **kwargs: KWArgs) -> None: self.log(C.LOG_LVL_WARNING, msg, **kwargs) - def error(self, msg, **kwargs): + def error(self, msg: object, **kwargs: KWArgs) -> None: self.log(C.LOG_LVL_ERROR, msg, **kwargs) - def critical(self, msg, **kwargs): + def critical(self, msg: object, **kwargs: KWArgs) -> None: self.log(C.LOG_LVL_CRITICAL, msg, **kwargs)