Movatterモバイル変換


[0]ホーム

URL:


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: Addhandler param tobasicConfig.#1023

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
greezybacon wants to merge1 commit intomicropython:master
base:master
Choose a base branch
Loading
fromgreezybacon:feature/logging-basicconfig-handler

Conversation

@greezybacon
Copy link
Contributor

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.

@stinos
Copy link

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

Josverl and thatbudakguy reacted with thumbs up emoji

@greezybacon
Copy link
ContributorAuthor

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.

@Josverl
Copy link

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 oflogging with basicConfig(handlers=<iterable>). This adds similar supportto Micropython. It allows to initialize logging with a set ofspecialized handlers.Signed-off-by: Jared Hancock <jared@greezybacon.me>
@greezybacongreezybaconforce-pushed thefeature/logging-basicconfig-handler branch from9d4e1ae to25185a5CompareJuly 18, 2025 12:47
Copy link
Member

@dpgeorgedpgeorge 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 thelogging module.

handler=StreamHandler(stream)
else:
handler=FileHandler(filename,filemode,encoding)
ifhandlersisNone:
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 neverNone unless explicitly passed in. Maybe you meantif not handlers?


handler.setLevel(level)
handler.setFormatter(Formatter(format,datefmt))
forhandlerinlogging.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 freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@dpgeorgedpgeorgedpgeorge 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.

4 participants

@greezybacon@stinos@Josverl@dpgeorge

[8]ページ先頭

©2009-2025 Movatter.jp