Skip to content

Commit 9d4e1ae

Browse files
committed
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>
1 parent 6e24cff commit 9d4e1ae

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

python-stdlib/logging/logging.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def basicConfig(
223223
format=None,
224224
datefmt=None,
225225
level=WARNING,
226+
handler=None,
226227
stream=None,
227228
encoding="UTF-8",
228229
force=False,
@@ -237,10 +238,14 @@ def basicConfig(
237238
h.close()
238239
logger.handlers = []
239240

240-
if filename is None:
241-
handler = StreamHandler(stream)
242-
else:
243-
handler = FileHandler(filename, filemode, encoding)
241+
if handler is not None:
242+
if filename is None:
243+
handler = StreamHandler(stream)
244+
else:
245+
handler = FileHandler(filename, filemode, encoding)
246+
elif stream or filename:
247+
raise ValueError("'stream' or 'filename' should not be "
248+
"specified together with 'handler'")
244249

245250
handler.setLevel(level)
246251
handler.setFormatter(Formatter(format, datefmt))

0 commit comments

Comments
 (0)