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

Use non-root python logger #194

Open
araistrick opened this issue Sep 9, 2023 · 1 comment
Open

Use non-root python logger #194

araistrick opened this issue Sep 9, 2023 · 1 comment

Comments

@araistrick
Copy link

araistrick commented Sep 9, 2023

My code does something akin to the following.

gin.add_config_file_search_path(folder1)
gin.add_config_file_search_path(folder2)
gin.parse_config_files_and_bindings(...)

I am now using gin from within code which is itself now packages as a pip-installable python package. Ever since executing this change, I now see logging output like the following:

INFO:root:system_path_file_exists:base_surface_registry.gin
ERROR:root:Path not found: base_surface_registry.gin
INFO:root:system_path_file_exists:natural.gin
ERROR:root:Path not found: natural.gin
INFO:root:system_path_file_exists:performance/dev.gin
ERROR:root:Path not found: performance/dev.gin
INFO:root:system_path_file_exists:disable_assets/no_creatures.gin
ERROR:root:Path not found: disable_assets/no_creatures.gin
INFO:root:system_path_file_exists:performance/fast_terrain_assets.gin
ERROR:root:Path not found: performance/fast_terrain_assets.gin

I would like to mute all gin-related logging, but it appears gin is using the root logging.info() rather than logger = logging.getLogger(__name__); logging.info(...) as is recommended.

Example:

logging.error('Path not found: %s', config_path)

Switching to the recommended getLogger(name) would allow me to logging.getLogger("gin").setLevel(logging.CRITICAL) to ignore these messages.

I could likely PR this if theres any chance of it being accepted.

@araistrick
Copy link
Author

For anyone else running into this issue I have gotten around it by wrapping gin.parse_config_files_and_bindings with a with LogLevel(logging.getLogger(), level=logging.CRITICAL) using the following implementation:

class LogLevel():

    def __init__(self, logger, level):
        self.logger = logger
        self.level = level
        self.orig_level = None

    def __enter__(self):
        self.orig_level = self.logger.level
        self.logger.setLevel(self.level)

    def __exit__(self, *_):
        self.logger.setLevel(self.orig_level)

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