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

Do not setup log handlers to write to stderr #758

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

draftcode
Copy link

By setting up a handler in the library, the library users do not have a good control on how/where to write the logs. Do not set a handler from the library.

By setting up a handler in the library, the library users do not have a
good control on how/where to write the logs. Do not set a handler from
the library.
@alexanderankin
Copy link
Member

alexanderankin commented Jan 15, 2025

@CarliJoy
Copy link
Contributor

CarliJoy commented Mar 4, 2025

@alexanderankin what do you mean with a logging overhaul?

Logging is always quite language specific as it requires global objects.

I am with draftcode that a libary should not setup a logger, it only should log.

I would even go that far, that the library should not even define the log level. It up to the user of the lib to define it.
But I see it is convenient to this. But at least do it in away, that is done exactly once during import for all modules.

I.e.

import logging
from typing import Final

LOGGER: Final = logging.getLogger("testcontainers")
LOGGER.setLevel(logging.INFO)

This would set the log level to all testcontainers logger (i.e. also testcontainers.core.utils).

Besides this, there is nothing more to do.

Why this is important

I am using testcontainers in pytest plugin, as I need containers to be started before imports are done (legacy code, that setups databases during import...).
And there is a long standing issues with pytest that doesn't handle it well when prints are happening in certain conditions.

So being able to simply disable/change the handler all together would be nice.

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.

3 participants