Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logging: CPython-compatible logging improvements #750

Closed

Conversation

ned-pcs
Copy link

@ned-pcs ned-pcs commented Oct 18, 2023

This commit allows for logging handlers to be added to the root logger and then used by non-root loggers that don't have their own handlers.

It also adds the (CPython-compatible) handlers argument to logging.basicConfig() to ease this initialization:

    import logging
    sh = logging.StreamHandler()
    fh = logging.FileHandler("my.log", mode="a")
    logging.basicConfig(handlers=[sh, fh])

    root_logger = logging.getLogger() # uses sh and fh
    another_logger = logging.getLogger("another") # inherits handlers

It also adds the Logger.removeHandler() method and avoids repeated handler addition.

It also correctly calls the superclass constructor from the StreamHandler constructor and uses a default formatter if a Handler has none set (as in PR #710).

@ned-pcs ned-pcs force-pushed the ned-pcs/fix-logging-handlers branch from e028c48 to 30d1a46 Compare December 1, 2023 16:03
@ned-pcs ned-pcs force-pushed the ned-pcs/fix-logging-handlers branch from 30d1a46 to dfdc686 Compare January 3, 2024 22:10
This commit allows for logging handlers to be added to the root logger
and then used by non-root loggers that don't have their own handlers.

It also adds the (CPython-compatible) handlers argument
to logging.basicConfig() to ease this initialization:

    import logging
    sh = logging.StreamHandler()
    fh = logging.FileHandler("my.log", mode="a")
    logging.basicConfig(handlers=[sh, fh])

    root_logger = logging.getLogger() # uses sh and fh
    another_logger = logging.getLogger("another") # inherits handlers


It also adds the Logger.removeHandler() method and avoids repeated handler
addition.

It also correctly calls the superclass constructor from the StreamHandler
constructor and uses a default formatter if a Handler has none
set (as in PR micropython#710).

Signed-off-by: Ned Konz <[email protected]>
This commit allows for logging handlers to be added to the root logger
and then used by non-root loggers that don't have their own handlers.

It also adds the (CPython-compatible) handlers argument
to logging.basicConfig() to ease this initialization:

    import logging
    sh = logging.StreamHandler()
    fh = logging.FileHandler("my.log", mode="a")
    logging.basicConfig(handlers=[sh, fh])

    root_logger = logging.getLogger() # uses sh and fh
    another_logger = logging.getLogger("another") # inherits handlers


It also adds the Logger.removeHandler() method and avoids repeated handler
addition.

It also adds the flush() method to StreamHandler and its subclasses.

It also correctly calls the superclass constructor from the StreamHandler
constructor and uses a default formatter if a Handler has none
set (as in PR micropython#710).

Signed-off-by: Ned Konz <[email protected]>
@ned-pcs
Copy link
Author

ned-pcs commented Feb 15, 2024

build failure appears to be due to manifest issues unrelated to this PR.

@ned-pcs
Copy link
Author

ned-pcs commented Feb 15, 2024

Closed; replaced with #806

@ned-pcs ned-pcs closed this Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant