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 doesn't propagate: trying to get all of ax messages to file #316

Closed
ksanjeevan opened this issue May 11, 2020 · 3 comments
Closed
Assignees
Labels
bug Something isn't working fixready Fix has landed on master.

Comments

@ksanjeevan
Copy link

I'm trying to run trials remotely and log the ax output to a file. From my main script I have:

...
fh = logging.FileHandler('out.log')
fh.setLevel(logging.INFO)

logging.getLogger('ax').addHandler(fh)
...

In other libraries this is enough to have all the logging be propagated to the root and then since I've added the handler, push them to a file. But with ax the log file is empty. I can see all the ax logger names:

print([k for k in logging.Logger.manager.loggerDict.keys() if k.startswith('ax')])
>>> ['ax.core.objective', 'ax.core', 'ax', 'ax.core.outcome_constraint', 'ax.core.experiment', 'ax.core.multi_type_experiment', 'ax.models.torch.botorch', 'ax.models.torch', 'ax.models', 'ax.modelbridge.transforms.int_to_float', 'ax.modelbridge.transforms', 'ax.modelbridge', 'ax.models.discrete.eb_thompson', 'ax.models.discrete', 'ax.models.discrete.full_factorial', 'ax.modelbridge.registry', 'ax.modelbridge.factory', 'ax.modelbridge.generation_strategy', 'ax.modelbridge.dispatch_utils', 'ax.service.utils.best_point', 'ax.service.utils', 'ax.service', 'ax.service.managed_loop', 'ax.benchmark.benchmark_problem', 'ax.benchmark', 'ax.benchmark.benchmark_result']

But adding a handler only works if I set it for each one individually, not just for the .getLogger('ax') root.
Looking at the code:

def get_logger(
it seems that in every submodule handlers and formatters are being set? Is that what's causing it not to propagate?

What are the best practices to follow if I want all of ax logging to be dumped to a file?

Thanks.

@Jakepodell
Copy link
Contributor

Hi @ksanjeevan! Thanks for bringing this to our attention. We have a few ideas of what the problem might be, but we will need to look into this further to get you a reliable solution. Thanks for your patience while we work on getting you an answer here!

@ldworkin ldworkin added the bug Something isn't working label May 14, 2020
@stevemandala
Copy link
Contributor

stevemandala commented Aug 27, 2020

Quick update @ksanjeevan: We refactored the core logger libraries in 44fdecb such that all Ax loggers inherit (and propagate) to the root logger "ax". With those change, this (similar to your example) should work:

# Same as logging.getLogger('ax')
from ax.utils.common.logger import get_root_logger()

fh = logging.FileHandler('out.log')
fh.setLevel(logging.INFO)

get_root_logger().addHandler(fh)

This is currently on master and should get included in the next release.

@ksanjeevan
Copy link
Author

Thanks for the update @stevemandala, I'll give it a shot!

@lena-kashtelyan lena-kashtelyan added the fixready Fix has landed on master. label Aug 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixready Fix has landed on master.
Projects
None yet
Development

No branches or pull requests

5 participants