Skip to content

Instantly share code, notes, and snippets.

@bradmontgomery
Created March 3, 2017 22:10
Show Gist options
  • Save bradmontgomery/c86ecffa070d041a3d084bb5103115f1 to your computer and use it in GitHub Desktop.
Save bradmontgomery/c86ecffa070d041a3d084bb5103115f1 to your computer and use it in GitHub Desktop.
quick & dirty example of logging in a single module. You could do similar things across all modules.
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG, filename="temp.log")
# ^^^ the filename param says print all log in a specified file.
def main():
logger.info("Getting Started")
for i in range(10):
logger.debug("processing {}".format(i))
if i == 7:
logger.warning("HEY, there's a 7")
items = []
try:
print(items[123])
except IndexError as e:
logger.error(e)
logger.info("Done")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment