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

Filters are removed when inside logging_redirect_tqdm context #1581

Open
5 of 6 tasks
danielnelson opened this issue May 9, 2024 · 0 comments
Open
5 of 6 tasks

Filters are removed when inside logging_redirect_tqdm context #1581

danielnelson opened this issue May 9, 2024 · 0 comments

Comments

@danielnelson
Copy link

  • I have marked all applicable categories:
    • exception-raising bug
    • visual output bug
  • I have visited the source website, and in particular
    read the known issues
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable:
    • Python 3.11.8
    • linux
    • tqdm 4.66.4

When using a logging.Filter, it seems to be not working when inside the logging_redirect_tqdm context manager. Here is an example:

import logging

from tqdm.contrib.logging import logging_redirect_tqdm


class Filter(logging.Filter):
    def filter(self, record):
        record.msg = f"{record.msg} -- filter"
        return True


filter = Filter()
handler = logging.StreamHandler()
handler.addFilter(filter)
logging.basicConfig(handlers=[handler])

logger = logging.getLogger("main")

logger.error("outside redirect")

with logging_redirect_tqdm():
    logger.error("inside redirect")

Expected output

ERROR:main:outside redirect -- filter
ERROR:main:inside redirect -- filter

Actual output

ERROR:main:outside redirect -- filter
ERROR:main:inside redirect

It looks like they just ought to be copied over from the original handler. If you like I can prepare a pull request.

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

No branches or pull requests

1 participant