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

Unable to disable logging for moldule blib2to3.pgen2.driver #2058

Closed
vlurgio opened this issue Mar 23, 2021 · 1 comment · Fixed by #3193
Closed

Unable to disable logging for moldule blib2to3.pgen2.driver #2058

vlurgio opened this issue Mar 23, 2021 · 1 comment · Fixed by #3193
Labels
T: bug Something isn't working

Comments

@vlurgio
Copy link

vlurgio commented Mar 23, 2021

Describe the bug A clear and concise description of what the bug is.
There is no way to disable logging of blib2to3.pgen2.driver class as the logger is created in the __init__ method and the optional logger isn't passed into the class from the top level black module. (driver is created on line 1130)
To Reproduce Steps to reproduce the behavior:

Anytime the format_str() function is called you get logging like

2021-03-23 18:52:48 blib2to3.pgen2.driver[86854] INFO Generating grammar tables from <filepath>
2021-03-23 18:52:48  blib2to3.pgen2.driver[86854] INFO Writing grammar tables to <filepath>
2021-03-23 18:52:48  blib2to3.pgen2.driver[86854] INFO Writing failed: [Errno 2] No such file or directory: '<filepath>
2021-03-23 18:52:48  blib2to3.pgen2.driver[86854] INFO Writing grammar tables to <filepath>
2021-03-23 18:52:48  blib2to3.pgen2.driver[86854] INFO Writing failed: [Errno 2] No such file or directory: <filepath>

The code I'm using is

from black import format_str, FileMode

format_str(out_string, mode=FileMode())

Expected behavior A clear and concise description of what you expected to happen.
using something like

import logging
logger = logging.getLogger("black")
logger.setLevel(logging.ERROR)

or even

import logging
logger = logging.getLogger("blib2to3")
logger.setLevel(logging.ERROR)

would disable logging
Environment (please complete the following information):

  • Version: 19.10b0
  • OS and Python version: Mac osx 3.6.9

Does this bug also happen on master? To answer this, you have two options:
The code still has logger being created in init on master so this problem still exists.

Additional context Add any other context about the problem here.

@saulshanabrook
Copy link

I was able to disable the logging with second example you posted: logging.getLogger("blib2to3").setLevel(logging.ERROR)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
3 participants