https://github.com/gixproject/simple-slack-logger
Python logging with Slack.
https://github.com/gixproject/simple-slack-logger
logging python slack
Last synced: about 2 months ago
JSON representation
Python logging with Slack.
- Host: GitHub
- URL: https://github.com/gixproject/simple-slack-logger
- Owner: gixproject
- License: apache-2.0
- Created: 2021-12-02T19:55:07.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-07T13:35:02.000Z (over 4 years ago)
- Last Synced: 2025-09-20T13:05:30.186Z (9 months ago)
- Topics: logging, python, slack
- Language: Python
- Homepage:
- Size: 13.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pypi.org/project/simple-slack-logger/)
[](https://github.com/ambv/black)
[](http://www.apache.org/licenses/LICENSE-2.0)
[](https://pypi.org/project/simple-slack-logger/)
[](https://www.codefactor.io/repository/github/gixproject/simple-slack-logger)
# Simple logging with Slack
It helps you to receive all logs from your Python code in Slack channels
using [webhooks](https://api.slack.com/messaging/webhooks).
Install from PyPi:
`pip install simple-slack-logger`
or from repository:
`pip install git+https://github.com/gixproject/simple-slack-logger `
## Usage
### Explicit usage
```python
import logging
from slack_logger import SlackHandler
logger = logging.getLogger(__name__)
handler = SlackHandler(webhook="")
logger.addHandler(handler)
logger.error("Something bad happened")
```
### Logging config
```python
"handlers": {
"slack": {
"class": "slack_logger.SlackHandler",
"formatter": "default",
"level": "WARNING",
"webhook": "",
},
}
```
### Hint
To catch all exceptions from your Python code you can use this in the main module:
```python
def logging_except_hook(exc_type, exc_value, exc_traceback):
logging.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
sys.excepthook = logging_except_hook
```