Skip to content

Instantly share code, notes, and snippets.

@isaacgr
Created June 7, 2019 16:03
Show Gist options
  • Save isaacgr/ad0380ba58df579d51ae81859db64223 to your computer and use it in GitHub Desktop.
Save isaacgr/ad0380ba58df579d51ae81859db64223 to your computer and use it in GitHub Desktop.
Setup logging for python scripts
import logging
FORMAT = "%(asctime)s:%(levelname)s:%(name)s:%(message)s"
datefmt = "%Y-%m-%d-%H:%M:%S"
log = logging.getLogger(__name__)
logging.basicConfig(filename="output.log", level=logging.INFO,
format=FORMAT, datefmt=datefmt)
def log_test():
log.info('Info')
log.warning('Warning')
log.critical('Critical')
if __name__ == '__main__':
log_test()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment