Created
March 3, 2017 22:10
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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