Easy methods to get Python logger to Print to std out

Should you use Python’s logger as follows:

import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG) # or logging.INFO

Maybe you wish to get it to print to Customary Output (stdout), then you are able to do the next:

Setup Logger to print to Customary Output

import logging

logger = logging.getLogger()
# logger.setLevel(logging.INFO)

handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter('%(asctime)s - %(identify)s - %(levelname)s - %(message)s')

This fashion now you can log straight to the console as properly:

logger.data('Some textual content will get logged right here')

Leave a Reply