Created
March 27, 2022 21:05
-
-
Save cobanov/cfc0c5a6232ec46869e1f9e3b65d4dff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import logging | |
logger = logging.getLogger("MyFileLogger") | |
log_path = os.path.join(os.getcwd(), "my_log.txt") | |
file_handler = logging.FileHandler(log_path) | |
formatter = logging.Formatter( | |
"%(asctime)s | %(name)-12s | %(levelname)-10s | %(message)s" | |
) | |
file_handler.setFormatter(formatter) | |
logger.addHandler(file_handler) | |
logger.warning("Oops something is going to happen") | |
logger.error("John Doe visits our place") | |
logger.critical("The system is down") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment