Answers for "python log file and console"

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
6

logging.logger

import logging

logging.basicConfig(level=logging.WARNING)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
  
logger.debug("some debugging...")
logger.error("some error...")
Posted by: Guest on December-02-2020

Code answers related to "python log file and console"

Python Answers by Framework

Browse Popular Code Answers by Language