Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use logging.DEBUG in PyCharm debug run

What is a good way to set the logging level for a module in pycharm so that debugging statements will print during a debug session? I am using the native python logging module in python 2.7.

like image 312
sakurashinken Avatar asked Mar 18 '26 01:03

sakurashinken


1 Answers

Python logging level can be set inside the Python module, not outside from PyCharm. Your Python application must adjust its own logging level.

  • Call logging.getLogger() to get the root logger (topmost in logging hierarchy)

  • Set environment variable in your run configuration in PyCharm. Detect this using os.environ.get("MYDEBUgVARNAME") and then call root.setLevel(logging.DEBUG). I am not sure if PyCharm itself sets any variable based on if it's normal or debug run.

For more information check my blog post for standard Python logging patters https://opensourcehacker.com/2016/05/22/python-standard-logging-pattern/

like image 62
Mikko Ohtamaa Avatar answered Mar 20 '26 00:03

Mikko Ohtamaa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!