Skip to content

Python logging stdout

  • by

The simplest way Python logging stdout is to use logging.basicConfig(). Use the helper function .basicConfig() to perform basic logging for the logging system.

import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

Python logging stdout

Simple example code If you need to print the messages to the stdout then logging.basicConfig is a handy shortcut for the configuration you listed. It will create a StreamHandler, attach the default Formatter to it and attach the handler to the root logger.

import logging
import sys

logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)
logging.getLogger().info('hi')

Output:

Python logging stdout

Do comment if you have any doubts or suggestions on this Python logging topic..

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading