From 25185a509db890274c987f126c7ef263fe163465 Mon Sep 17 00:00:00 2001 From: Jared Hancock Date: Wed, 11 Jun 2025 07:35:43 -0500 Subject: [PATCH] logging: Add `handlers` param to `basicConfig`. CPython allows specifying a list of handlers in the initialization of logging with basicConfig(handlers=). This adds similar support to Micropython. It allows to initialize logging with a set of specialized handlers. Signed-off-by: Jared Hancock --- python-stdlib/logging/logging.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/python-stdlib/logging/logging.py b/python-stdlib/logging/logging.py index 551bf7152..33f8e5b14 100644 --- a/python-stdlib/logging/logging.py +++ b/python-stdlib/logging/logging.py @@ -223,6 +223,7 @@ def basicConfig( format=None, datefmt=None, level=WARNING, + handlers=(), stream=None, encoding="UTF-8", force=False, @@ -235,19 +236,24 @@ def basicConfig( if force or not logger.handlers: for h in logger.handlers: h.close() - logger.handlers = [] + logger.handlers = list(handlers) - if filename is None: - handler = StreamHandler(stream) - else: - handler = FileHandler(filename, filemode, encoding) + if handlers is 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 'handlers'") - handler.setLevel(level) - handler.setFormatter(Formatter(format, datefmt)) + for handler in logging.handlers: + handler.setLevel(level) + handler.setFormatter(Formatter(format, datefmt)) - logger.setLevel(level) - logger.addHandler(handler) + logger.addHandler(handler) + logger.setLevel(level) if hasattr(sys, "atexit"): sys.atexit(shutdown) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy