import logging
import sys
logger = logging.getLogger(__name__)
console_handler = logging.StreamHandler(sys.stdout)
file_handler = logging.FileHandler("debug.log")
console_handler.setLevel(logging.INFO)
file_handler.setLevel(logging.DEBUG)
console_formatter = logging.Formatter('%(message)s')
file_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console_handler.setFormatter(console_formatter)
file_handler.setFormatter(file_formatter)
logger.addHandler(console_handler)
logger.addHandler(file_handler)
logger.setLevel(logging.DEBUG) #set root logging level to DEBUG
if __name__ == "__main__":
x = 4
y = 5
logger.debug("X: %s", x)
logger.debug("Y: %s", y)
logger.info("x is {}".format(x))
logger.info("y is {}".format(y))
logger.info("x * y = {}".format(x * y))
logger.info("x^y = {}".format(x ** y))
2021-02-01 15:12:10,427 - __main__ - DEBUG - X: 4
2021-02-01 15:12:10,428 - __main__ - DEBUG - Y: 5
2021-02-01 15:12:10,428 - __main__ - INFO - x is 4
2021-02-01 15:12:10,428 - __main__ - INFO - y is 5
2021-02-01 15:12:10,428 - __main__ - INFO - x * y = 20
2021-02-01 15:12:10,428 - __main__ - INFO - x^y = 1024
2021-02-01 15:48:04,392 - __main__ - DEBUG - X: 4
2021-02-01 15:48:04,392 - __main__ - DEBUG - Y: 5
2021-02-01 15:48:04,392 - __main__ - INFO - x is 4
2021-02-01 15:48:04,392 - __main__ - INFO - y is 5
2021-02-01 15:48:04,392 - __main__ - INFO - x * y = 20
2021-02-01 15:48:04,392 - __main__ - INFO - x^y = 1024
2021-02-05 14:55:57,164 - __main__ - DEBUG - X: 4
2021-02-05 14:55:57,164 - __main__ - DEBUG - Y: 5
2021-02-05 14:55:57,165 - __main__ - INFO - x is 4
2021-02-05 14:55:57,165 - __main__ - INFO - y is 5
2021-02-05 14:55:57,165 - __main__ - INFO - x * y = 20
2021-02-05 14:55:57,165 - __main__ - INFO - x^y = 1024