import logging logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) logger.info("This is an informational message")
import logging logging.basicConfig(filename='example.log',level=logging.INFO) logger = logging.getLogger(__name__) logger.info("This is an informational message saved to a file")Package Library: Python's inbuilt logging module is used to implement logging in a program. As the logger is the built-in Python library, no external package or library installation is needed.