Skip to content

Instantly share code, notes, and snippets.

@noahp
Created January 12, 2016 13:53
Show Gist options
  • Save noahp/f14e6fb6c906b607a273 to your computer and use it in GitHub Desktop.
Save noahp/f14e6fb6c906b607a273 to your computer and use it in GitHub Desktop.
# https://docs.python.org/2/howto/logging-cookbook.html#logging-to-multiple-destinations
if not None:
# set up logging to screen and file
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s', filename='log.log')
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# set a format which is simpler for console use
formatter = logging.Formatter('%(asctime)s %(message)s')
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
else:
# set up logging to screen only
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
logging.info("Starting test sequence.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment