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()
    ]
)

Here is what the above code is Doing:
1. We’re creating a basic config for our logger.
2. We’re setting the logging level to INFO.
3. We’re setting the format of our log messages.
4. We’re adding a FileHandler to our logger.
5. We’re adding a StreamHandler to our logger.