在Python中,有多种方法可以打印日志,常用的方法包括:
print("This is a log message")
import logging
logging.basicConfig(level=logging.INFO)
logging.info("This is a log message")
import logging
logging.basicConfig(filename='logfile.log', level=logging.INFO)
logging.info("This is a log message")
from loguru import logger
logger.add("logfile.log", format="{time} {level} {message}", level="INFO")
logger.info("This is a log message")
这些方法可以根据需要选择适合的方式打印日志信息。