Skip to main content

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

  1. 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

  1. Import Google Chat Handler

    • from google_chat_handler import GoogleChatHandler
  2. Initialize the chat handler

    • handler = GoogleChatHandler('https://chat.googleapis.com/v1/spaces/xxxxxxx')
  3. 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)
  4. Add the handler to the existing logger

    • logger.addHandler(handler)
  5. 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")

Metadata

Release files for google-chat-handler 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for google-chat-handler 1.0.1
File Size Uploaded
google_chat_handler-1.0.1.tar.gz 3.4 kB Details

Release files / google_chat_handler-1.0.1.tar.gz

Download URL google_chat_handler-1.0.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ef256ab5aca6b69f23c59616c3bd9ce3ebb75ea39d9da52c785511ae12504638
BLAKE2b-256 checksum
How to use checksums
7354bfc7e6a2d446e73ddce071b813b6e8f89e008b820b7416f2f8738bffd2c7
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

1.0.1 This release

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page