From 3a6d5a3129a824c69e84f8db1c8836e083f14707 Mon Sep 17 00:00:00 2001 From: waldek Date: Mon, 7 Jun 2021 10:11:17 +0200 Subject: [PATCH] adds logging snippet --- modules/qualifying/learning_python3.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/modules/qualifying/learning_python3.md b/modules/qualifying/learning_python3.md index c0145b8..e6a03c8 100644 --- a/modules/qualifying/learning_python3.md +++ b/modules/qualifying/learning_python3.md @@ -74,3 +74,26 @@ There are no *rules* as to what has to be included for a program to qualify as a Our text editor of choice, `vim-nox` comes with some of these features and we can add more with plugins so vim can [become](https://dev.to/shahinsha/how-to-make-vim-a-python-ide-best-ide-for-python-23e1) an IDE if we want it to. To make the overall learning curve a bit less steep we'll start out with a more user friendly IDE, [pycharm](https://www.jetbrains.com/help/pycharm/installation-guide.html). +## Snippets + +### Logging + +```python3 +import logging + +logger = logging.root +format = "%(asctime)s - %(levelname)-10s - %(name)s - %(filename)s - %(funcName)s - %(message)s" +formatter = logging.Formatter(format) + +st_handler = logging.StreamHandler() +st_handler.setFormatter(formatter) + +logger.addHandler(st_handler) + +logger.setLevel(logging.DEBUG) + +logger.info("hello world") +logger.debug("I'm a debug message") +logger.error("I'm an error message") +logger.critical("I'm a critical message") +```