Below is a basic configuration for the loguru logging library. It includes logging to both the console and a file, with separate levels and formatting.
# Add a file logger logger.add( sink="app.log", level="DEBUG", # Log level for file format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}", rotation="10 MB", # Rotate logs every 10 MB retention="7 days", # Retain logs for 7 days compression="zip", # Compress old log files enqueue=True, # Thread-safe )
# Example usage if __name__ == "__main__": logger.debug("This is a debug message.") logger.info("This is an info message.") logger.warning("This is a warning message.") logger.error("This is an error message.") logger.critical("This is a critical message.")