black icon indicating copy to clipboard operation
black copied to clipboard

Unable to disable logging for moldule blib2to3.pgen2.driver

Open vlurgio opened this issue 5 years ago • 1 comments

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.

vlurgio avatar Mar 23 '21 23:03 vlurgio

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

saulshanabrook avatar Oct 12 '21 14:10 saulshanabrook