Mercurial > libervia-backend
comparison sat/core/log.py @ 3997:1b7c6ee080b9
core (log): type hints
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 04 Mar 2023 18:23:33 +0100 |
parents | 760f563b1243 |
children | 524856bd7b19 |
comparison
equal
deleted
inserted
replaced
3996:7a6c7abd7dbb | 3997:1b7c6ee080b9 |
---|---|
19 | 19 |
20 """High level logging functions""" | 20 """High level logging functions""" |
21 # 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. | 21 # 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. |
22 # TODO: change formatting from "%s" style to "{}" when moved to Python 3 | 22 # TODO: change formatting from "%s" style to "{}" when moved to Python 3 |
23 | 23 |
24 from typing import TYPE_CHECKING, Any, Optional | 24 from typing import TYPE_CHECKING, Any, Optional, Dict |
25 | 25 |
26 if TYPE_CHECKING: | 26 if TYPE_CHECKING: |
27 from logging import _ExcInfoType | 27 from logging import _ExcInfoType |
28 else: | 28 else: |
29 _ExcInfoType = Any | 29 _ExcInfoType = Any |
32 from sat.tools.common.ansi import ANSI as A | 32 from sat.tools.common.ansi import ANSI as A |
33 from sat.core import exceptions | 33 from sat.core import exceptions |
34 import traceback | 34 import traceback |
35 | 35 |
36 backend = None | 36 backend = None |
37 _loggers = {} | 37 _loggers: Dict[str, "Logger"] = {} |
38 handlers = {} | 38 handlers = {} |
39 COLOR_START = '%(color_start)s' | 39 COLOR_START = '%(color_start)s' |
40 COLOR_END = '%(color_end)s' | 40 COLOR_END = '%(color_end)s' |
41 | 41 |
42 | 42 |
399 def memoryGet(size=None): | 399 def memoryGet(size=None): |
400 if not C.LOG_OPT_OUTPUT_MEMORY in handlers: | 400 if not C.LOG_OPT_OUTPUT_MEMORY in handlers: |
401 raise ValueError('memory output is not used') | 401 raise ValueError('memory output is not used') |
402 return configure_cls[backend].memoryGet(size) | 402 return configure_cls[backend].memoryGet(size) |
403 | 403 |
404 def getLogger(name=C.LOG_BASE_LOGGER): | 404 def getLogger(name=C.LOG_BASE_LOGGER) -> Logger: |
405 try: | 405 try: |
406 logger_class = configure_cls[backend].LOGGER_CLASS | 406 logger_class = configure_cls[backend].LOGGER_CLASS |
407 except KeyError: | 407 except KeyError: |
408 raise ValueError("This method should not be called with backend [{}]".format(backend)) | 408 raise ValueError("This method should not be called with backend [{}]".format(backend)) |
409 return _loggers.setdefault(name, logger_class(name)) | 409 return _loggers.setdefault(name, logger_class(name)) |