import logging # Setting up the logger logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) # Creating a file handler handler = logging.FileHandler('info.log') handler.setLevel(logging.INFO) # Creating a formatter formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) # Adding the handler to the logger logger.addHandler(handler) # Logging an informative message logger.info("This is an informative message")
import logging # Setting up the logger logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) # Logging an informative message logger.info("This is an informative message") # Message is printed to consoleIn this example, we are using the LOGGER info method to write an informational message to the console. The logger instance is set up and we just need to call the LOGGER info method to log the message. Package Library: The LOGGER info method is part of the standard logging module in Python.