Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing logging output in Python

Tags:

python

logging

I have an issue with Python logging and I'm not sure what the problem is as the same line of code used to work just fine yesterday.

So for example the following code only produces output for the print function but not for logging.

Any ideas?

import logging

if __name__ == '__main__':
    logging.basicConfig(level = logging.DEBUG)
    logging.info("Hello, World!")
    print "Hello, World!"
like image 307
Gabor Avatar asked Jun 29 '26 22:06

Gabor


1 Answers

You can try this alternative:

>>> import logging
>>> logging.getLogger().setLevel(logging.INFO)
>>> logging.info("Hello, World!")
INFO:root:Hello, World!

Here you are setting to the root logger the info level.

like image 137
jvallver Avatar answered Jul 01 '26 11:07

jvallver