Skip to content

Instantly share code, notes, and snippets.

@cobanov
Created March 27, 2022 21:05
Show Gist options
  • Save cobanov/cfc0c5a6232ec46869e1f9e3b65d4dff to your computer and use it in GitHub Desktop.
Save cobanov/cfc0c5a6232ec46869e1f9e3b65d4dff to your computer and use it in GitHub Desktop.
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