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,
|
format=None,
|
||||||
datefmt=None,
|
datefmt=None,
|
||||||
level=WARNING,
|
level=WARNING,
|
||||||
|
handler=None,
|
||||||
stream=None,
|
stream=None,
|
||||||
encoding="UTF-8",
|
encoding="UTF-8",
|
||||||
force=False,
|
force=False,
|
||||||
|
@ -237,10 +238,14 @@ def basicConfig(
|
||||||
h.close()
|
h.close()
|
||||||
logger.handlers = []
|
logger.handlers = []
|
||||||
|
|
||||||
if filename is None:
|
if handler is not None:
|
||||||
handler = StreamHandler(stream)
|
if filename is None:
|
||||||
else:
|
handler = StreamHandler(stream)
|
||||||
handler = FileHandler(filename, filemode, encoding)
|
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.setLevel(level)
|
||||||
handler.setFormatter(Formatter(format, datefmt))
|
handler.setFormatter(Formatter(format, datefmt))
|
||||||
|
|
Ładowanie…
Reference in New Issue