Answers for "python log message to console and log file"

1

python logging to console exqmple

import sys
# ...
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))
Posted by: Guest on January-04-2021
2

python log to file and console

import logging

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s [%(levelname)s] %(message)s",
    handlers=[
        logging.FileHandler("debug.log"),
        logging.StreamHandler()
    ]
)
Posted by: Guest on April-07-2020
2

python log file

import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
Posted by: Guest on June-14-2021

Code answers related to "python log message to console and log file"

Python Answers by Framework

Browse Popular Code Answers by Language