Skip to content

Instantly share code, notes, and snippets.

@Priyanshu9898
Created March 7, 2023 13:19
Show Gist options
  • Save Priyanshu9898/63846e45fb489093550c0ce2e4690b69 to your computer and use it in GitHub Desktop.
Save Priyanshu9898/63846e45fb489093550c0ce2e4690b69 to your computer and use it in GitHub Desktop.
Code for Logger file
import logging
import os
from datetime import datetime
LOG_FILE=f"{datetime.now().strftime('%m_%d_%Y_%H_%M_%S')}.log"
logs_path=os.path.join(os.getcwd(),"logs",LOG_FILE)
os.makedirs(logs_path,exist_ok=True)
LOG_FILE_PATH=os.path.join(logs_path,LOG_FILE)
logging.basicConfig(
filename=LOG_FILE_PATH,
format="[ %(asctime)s ] %(lineno)d %(name)s - %(levelname)s - %(message)s",
level=logging.INFO,
)
if __name__ == "__main__":
logging.info("Logging has started.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment