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 Commonplace Output (stdout), then you are able to do the next:

Setup Logger to print to Commonplace Output#

import logging

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

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

This manner now you can log straight to the console as nicely:

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