Log data in google chat
Project description
Google Chat Handler
Python logging handler to push the logs to google chat root using the webhook url. Just create a room or use existing room and create a webhook url of a bot and pass the URL to this GoogleChatHandler library.
Installation Instruction!
- Activate your Virtual Environment.
pip install google_chat_handler
Features
- Google chat handler library give us the GoogleChatHandler class that we have to use and attach the handler to any logger of class logging. It is also compatible with flask and django logger.
Usage
-
Import Google Chat Handler
from google_chat_handler import GoogleChatHandler
-
Initialize the chat handler
handler = GoogleChatHandler('https://chat.googleapis.com/v1/spaces/xxxxxxx')
-
Set the level of the handler
- let say if we want to push only error logs to google chat as a alert
handler.setLevel(logging.ERROR)
-
Add the handler to the existing logger
logger.addHandler(handler)
-
Now use the google chat handler
logger.error("This message will appear in google chat")
Example
import logging
from google_chat_handler import GoogleChatHandler
# logger of your project
# Get default logger
logger = logging.getLogger()
# set default level of the logger
logger.setLevel(logging.DEBUG)
# Create google_chat_handler for google chat google_chat_handler
handler = GoogleChatHandler(webhook_url="https://chat.googleapis.com/v1/spaces/XXXXXXXXX")
# Set level of the Google chat google_chat_handler for which loglevel we have to send logs to google
handler.setLevel(logging.ERROR)
# Add the google_chat_handler to the logger
logger.addHandler(handler)
logger.info("normal logger info")
logger.debug("normal logger debug")
# Only below log will be pushed to google chat
logger.error("google chat logger error")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file google_chat_handler-1.0.1.tar.gz
.
File metadata
- Download URL: google_chat_handler-1.0.1.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef256ab5aca6b69f23c59616c3bd9ce3ebb75ea39d9da52c785511ae12504638 |
|
MD5 | a530a90a6f9c9d50fc448930e5c31d6c |
|
BLAKE2b-256 | 7354bfc7e6a2d446e73ddce071b813b6e8f89e008b820b7416f2f8738bffd2c7 |