0

I'm trying to import from the following module: https://github.com/dmlc/gluon-cv/blob/master/gluoncv/torch/data/gluoncv_motion_dataset/dataset.py

However this includes the lines:

logging.basicConfig(level=logging.INFO)
log = logging.getLogger()

Which is messing up the logging settings I'm trying to apply in my main file. How can I import from this module, but overwrite the above log settings?

Austin
  • 6,921
  • 12
  • 73
  • 138
  • Does this answer your question? [Python Logging - Disable logging from imported modules](https://stackoverflow.com/questions/35325042/python-logging-disable-logging-from-imported-modules) – Woodford Sep 24 '21 at 16:37
  • Thanks but no, I tried that, and it ends up using both the root logger which prints to console, as well as my logger which doesn't – Austin Sep 24 '21 at 16:57
  • Post an MRE. It's not clear exactly what's going wrong. If you're importing that file and then setting your own logging config you should be overwriting their settings, not the other way around. – Woodford Sep 24 '21 at 19:34
  • 1
    just open that file and comment out the `logging.basicConfig` line – dragon2fly Sep 25 '21 at 04:03
  • 1
    It's great you logged an issue with them, I've added a comment there about how calling `basicConfig()` in a library module is bad practice. – Vinay Sajip Sep 25 '21 at 06:40
  • Thanks. Ended up importing `log` object from module and setting `log.handlers = []`. Probably a fine workaround until they modify the module. – Austin Sep 25 '21 at 16:42
  • You could also put the import after you do your own logging setup. basicConfig has no effect if a logger is already configured. – blues Sep 25 '21 at 18:59
  • Hmmm I thought I tried putting the import after without success, but thanks I can try that again – Austin Sep 26 '21 at 15:07

0 Answers0