Skip to content

Instantly share code, notes, and snippets.

@RichardDally
Created August 21, 2023 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardDally/cbe16e8a71d5cbb5b4dee90aa6e1647c to your computer and use it in GitHub Desktop.
Save RichardDally/cbe16e8a71d5cbb5b4dee90aa6e1647c to your computer and use it in GitHub Desktop.
Python standard logger bootstrap
import sys
import logging
from datetime import datetime
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s.%(msecs)03d | %(levelname)s | %(module)s.%(funcName)s | %(message)s",
datefmt="%Y/%m/%d %H:%M:%S",
handlers=[
logging.FileHandler(datetime.now().strftime('%Y%m%d_%H%M%S.log')),
logging.StreamHandler(sys.stdout),
]
)
def main():
logging.info("Hello Python standard logger !")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment