adds logging snippet

This commit is contained in:
waldek 2021-06-07 10:11:17 +02:00
parent 9996859a37
commit 3a6d5a3129
1 changed files with 23 additions and 0 deletions

View File

@ -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. 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). 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")
```