Skip to content

Instantly share code, notes, and snippets.

@easternnl
Created March 31, 2020 04:17
Show Gist options
  • Save easternnl/d8babe49b3fb7091e233701363091882 to your computer and use it in GitHub Desktop.
Save easternnl/d8babe49b3fb7091e233701363091882 to your computer and use it in GitHub Desktop.
Python logging to file and to console - as in https://stackoverflow.com/a/46098711
import logging
# remove '%(created)f' to avoid logging the timestamp in epoch
logging.basicConfig(level='INFO',
format='%(asctime)s %(created)f %(message)s',
handlers=[
logging.FileHandler(datetime.now().strftime(testrun + ".log")),
logging.StreamHandler()
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment