Skip to content

Instantly share code, notes, and snippets.

@abhi1010
Created June 19, 2018 03:07
Show Gist options
  • Save abhi1010/786ecdc2f5e0f8bf742412b7beaefa07 to your computer and use it in GitHub Desktop.
Save abhi1010/786ecdc2f5e0f8bf742412b7beaefa07 to your computer and use it in GitHub Desktop.
python logging to console and file
import logging
FORMAT = '%(asctime)-15s %(filename)s <%(lineno)s> %(message)s'
logging.basicConfig(
filename='log-myreport.log', level=logging.DEBUG, format=FORMAT)
stdoutLogger = logging.StreamHandler()
stdoutLogger.setFormatter(logging.Formatter(logging.BASIC_FORMAT))
logging.getLogger().addHandler(stdoutLogger)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment