kopia lustrzana https://github.com/micropython/micropython-lib
logging: Add `handler` param to `basicConfig`.
CPython allows specifying a list of handlers in the initialization of logging with basicConfig(handlers=<iterable>). This adds similar support but only with a single handler. It allows to initialize logging with a single, specialized handler. Signed-off-by: Jared Hancock <jared@greezybacon.me>pull/1023/head
rodzic
6e24cffe95
commit
9d4e1ae34d
|
@ -223,6 +223,7 @@ def basicConfig(
|
|||
format=None,
|
||||
datefmt=None,
|
||||
level=WARNING,
|
||||
handler=None,
|
||||
stream=None,
|
||||
encoding="UTF-8",
|
||||
force=False,
|
||||
|
@ -237,10 +238,14 @@ def basicConfig(
|
|||
h.close()
|
||||
logger.handlers = []
|
||||
|
||||
if handler is not None:
|
||||
if filename is None:
|
||||
handler = StreamHandler(stream)
|
||||
else:
|
||||
handler = FileHandler(filename, filemode, encoding)
|
||||
elif stream or filename:
|
||||
raise ValueError("'stream' or 'filename' should not be "
|
||||
"specified together with 'handler'")
|
||||
|
||||
handler.setLevel(level)
|
||||
handler.setFormatter(Formatter(format, datefmt))
|
||||
|
|
Ładowanie…
Reference in New Issue