0

I have a python script with a cli argument parser (based on argparse) I am calling it from a batch file:

set VAR1=arg_1
set VAR2=arg_2

python script.py --arg1 %VAR1% --arg2 %VAR2%

within the script.py I call a logger:

logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
  • This script utilizes chromedriver, selenium and requests to automate some clicking and moving between web pages.
  • When running from within PyCharm (configured so that the script has arg_1 and arg_2 passed to it) everything is great - I get log messages from my logger only.
  • When I run the batch file - I get a bunch of logging messages from chromedriver or requests (I think).

I have tried:

  • @echo off at the start of the batch file.
  • Setting the level on the root logger.
  • Getting the logging logger dictionary and setting each logger to WARNING - based on this question.

None of these work and I keep getting logging messages from submodules - ONLY when run from a batch file.

Anybody know how to fix this?

double-beep
  • 5,031
  • 17
  • 33
  • 41
Jack G
  • 96
  • 9

1 Answers1

0

You can use the following configuration options to do this

import logging.config
logging.config.dictConfig({
    'version': 1,
    'disable_existing_loggers': True,
})
Shashank Verma
  • 369
  • 1
  • 14
  • This did not work. I think the logs are coming from chromedriver (or chrome itself) because I only see it when run from command line. From PyCharm I don't see these logs... – Jack G Dec 11 '18 at 20:20
  • Are you setting the logs inside if __name__ == "__main__" ? If yes, move the logging config outside that. If not, please add the extra logs in your question that you want to remove to get a clear idea of where the logs might be coming from. – Shashank Verma Dec 12 '18 at 06:57