python log message to console and log file code example
Example 1: 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()
]
)
Example 2: python logging to console exqmple
import sys
# ...
logging.getLogger().addHandler(logging.StreamHandler(sys.stdout))