So, I want to control the verbosity of the logger. I know that I can do this via logging.basicConfig
. Currently, I have the following code which works fine:
import logging
from argparse import ArgumentParser
logger = None
class MyClass:
def __init__(self):
logger.info('initialized')
def main():
parser = ArgumentParser()
parser.add_argument('--verbose', default=False, action='store_true')
args = parser.parse_args()
global logger
if args.verbose:
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.DEBUG)
else:
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.INFO)
logger = logging.getLogger('mylogger')
myclass = MyClass()
if __name__ == '__main__':
main()
However, I get the pylint
error:
Redefining name 'logger' from outer scope (line 3) (redefined-outer-name)
What is the best way to achieve this without any pylint errors?