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

Globally setting the logging level in in gym_unity/envs/__init__.py conflicts with user setting. #4987

Closed
julienroyd opened this issue Feb 22, 2021 · 3 comments
Assignees
Labels
bug Issue describes a potential bug in ml-agents. stale Issues that have been idle for a while. Automatically closed by a bot if idle for too long.

Comments

@julienroyd
Copy link

julienroyd commented Feb 22, 2021

I am using Python 3.7.4 and gym_unity==0.23.0

In gym_unity/envs/__init__.py, the logging level is set globally:
https://github.com/Unity-Technologies/ml-agents/blob/master/gym-unity/gym_unity/envs/__init__.py#L22

This causes the logging settings to be overwritten for loggers defined by the users simply by importing the UnityToGymWrapper and leads to double printing (in red) in the console. Here is a minimal example to reproduce the issue:

import logging
import sys

from gym_unity.envs import UnityToGymWrapper

def create_logger(name, loglevel):
    logger = logging.getLogger(name)
    logger.setLevel(loglevel)
    handler = logging.StreamHandler(stream=sys.stdout)
    formatter = logging.Formatter(fmt=f'%(asctime)s - {name} - %(message)s', datefmt='%d/%m/%Y %H:%M:%S')
    handler.setFormatter(formatter)
    logger.addHandler(handler)
    return logger

if __name__ == "__main__":
    logger = create_logger(name="USER LOGGER", loglevel=logging.INFO)
    for i in range(10):
        logger.info(f"i={i}")

Which outputs:

output

(commenting out from gym_unity.envs import UnityToGymWrapper resolves the issue)

Suggested fix:

By simply setting the logging level for the logger instance only seem to solve the issue (Line 22 of gym_unity/envs/__init__.py):

logger.setLevel(logging.INFO)

@julienroyd julienroyd added the bug Issue describes a potential bug in ml-agents. label Feb 22, 2021
@andrewcoh andrewcoh self-assigned this Feb 23, 2021
@stale
Copy link

stale bot commented Apr 17, 2022

This issue has been automatically marked as stale because it has not had activity in the last 28 days. It will be closed in the next 14 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issues that have been idle for a while. Automatically closed by a bot if idle for too long. label Apr 17, 2022
@stale
Copy link

stale bot commented May 1, 2022

This issue has been automatically closed because it has not had activity in the last 42 days. If this issue is still valid, please ping a maintainer. Thank you for your contributions.

@stale stale bot closed this as completed May 1, 2022
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue describes a potential bug in ml-agents. stale Issues that have been idle for a while. Automatically closed by a bot if idle for too long.
Projects
None yet
Development

No branches or pull requests

2 participants