Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

logging: Add handler param to basicConfig.#1023

Open
greezybacon wants to merge 1 commit intomicropython:master from
greezybacon:feature/logging-basicconfig-handler
Open

logging: Add handler param to basicConfig. #1023
greezybacon wants to merge 1 commit intomicropython:master from
greezybacon:feature/logging-basicconfig-handler

Conversation

@greezybacon
Copy link
Contributor

@greezybacon greezybacon commented Jun 11, 2025

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.

Copy link

stinos commented Jun 11, 2025

It seems like a small step to just support handlers then, such that the code should remains compatible with CPython?

Josverl and thatbudakguy reacted with thumbs up emoji

Copy link
Contributor Author

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.

Copy link
Contributor

Josverl commented Jun 12, 2025

I agree that handlers = [] is simpler to learn ,
it also means that adding
Logger.addHandler() makes more sense.

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>
@greezybacon greezybacon force-pushed the feature/logging-basicconfig-handler branch from 9d4e1ae to 25185a5 Compare July 18, 2025 12:47
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging is not defined in this scope.

handler.setFormatter(Formatter(format, datefmt))

logger.setLevel(level)
logger.addHandler(handler)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the default handler (if none specified) is never added?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dpgeorge dpgeorge dpgeorge left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /