I have the following simple test script:
import logging
import sys
logger = logging.getLogger(__name__)
handler = logging.StreamHandler(sys.stdout)
handler.setLevel(logging.INFO)
handler.setFormatter(logging.Formatter('%(name)s - %(levelname)s - %(message)s'$
logger.addHandler(handler)
logger.info('Hello World!')
logger.warning('Bad!')
I run this script with python test.py
in the command line. I get:
__main__ - WARNING - Bad!
When I expected to get:
__main__ - WARNING - Bad!
__main__ - INFO - Hello World!
E.g. I expected both the info
and warning
log messages to get printed to the console window, but only the warning
message did. How come?