logging: Add handler param to basicConfig.#1023
logging: Add handler param to basicConfig.#1023greezybacon wants to merge 1 commit intomicropython:masterfrom
handler param to basicConfig.#1023Conversation
|
It seems like a small step to just support |
|
I could do that, yeah. My thought was that for an MCU more than one handler is unlikely, but I agree that compatibility means that everyone feels more comfortable using Micropython. |
|
I agree that handlers = [] is simpler to learn , |
CPython allows specifying a list of handlers in the initialization of logging with basicConfig(handlers=<iterable>). This adds similar support to Micropython. It allows to initialize logging with a set of specialized handlers. Signed-off-by: Jared Hancock <jared@greezybacon.me>
9d4e1ae to
25185a5
Compare
dpgeorge
left a comment
There was a problem hiding this comment.
This is a nice enhancement, but the implementation doesn't work.
We really need some unittests for the logging module.
| handler = StreamHandler(stream) | ||
| else: | ||
| handler = FileHandler(filename, filemode, encoding) | ||
| if handlers is None: |
There was a problem hiding this comment.
This doesn't seem right: handlers is never None unless explicitly passed in. Maybe you meant if not handlers?
|
|
||
| handler.setLevel(level) | ||
| handler.setFormatter(Formatter(format, datefmt)) | ||
| for handler in logging.handlers: |
There was a problem hiding this comment.
logging is not defined in this scope.
| handler.setFormatter(Formatter(format, datefmt)) | ||
|
|
||
| logger.setLevel(level) | ||
| logger.addHandler(handler) |
There was a problem hiding this comment.
It looks like the default handler (if none specified) is never added?
CPython allows specifying a list of handlers in the initialization of logging with basicConfig(handlers=). This adds similar support but only with a single handler. It allows to initialize logging with a single, specialized handler.