A python logging handler that logs to Webex incoming webhooks
Project description
Webex Logging Handler
This is a simple Python logging handler that emits messages to Webex incoming Webhooks.
Installing
To install run:
python -m pip install git+https://github.com/xorrkaz/webex-log-handler.git
Usage
First, obtain an incoming webhook URL from https://apphub.webex.com/messaging/applications/incoming-webhooks-cisco-systems-38054.
Here is a trivial usage. But you'll likely want to use a logger.conf or the like.
import logging
from webex_handler import WebexHandler
logger = logging.getLogger(__name__)
# The notice level is more severe than INFO but not as severe as WARNING.
logger.setLevel(WebexHandler.NOTICE)
logging.addLevelName(WebexHandler.NOTICE, "NOTICE")
wx = WebexHandler("https://webexapis.com/v1/webhooks/incoming/...")
wx.setLevel(WebexHandler.NOTICE)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
wx.setFormatter(formatter)
logger.addHandler(wx)
logger.log(WebexHandler.NOTICE, "Logging from Python!")
If you are using asyncio, there is an async version of the handler as well. It requires the aiolog and aiohttp packages, though. To use it:
pip install aiolog aiohttp
import asyncio
import aiolog
import logging
from webex_handler import AsyncWebexHandler
logger = logging.getLogger(__name__)
# The notice level is more severe than INFO but not as severe as WARNING.
logger.setLevel(AsyncWebexHandler.NOTICE)
logging.addLevelName(AsyncWebexHandler.NOTICE, "NOTICE")
wx = AsyncWebexHandler("https://webexapis.com/v1/webhooks/incoming/...")
wx.setLevel(AsyncWebexHandler.NOTICE)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
wx.setFormatter(formatter)
logger.addHandler(wx)
async def do_work():
logger.log(AsyncWebexHandler.NOTICE, "Logging from Python!")
aiolog.start()
loop = asyncio.get_event_loop()
loop.run_until_complete(do_work())
loop.run_until_complete(aiolog.stop())
Et voilà!
Other Info
The WebexHandler uses markdown-formatted messages by default, but you can pass use_markdown=False to the WebexHandler constructor to use plain text.
Also, be cognizant than a high level (like INFO or DEBUG) can make things very chatty in Webex. Consider a lower level to minimize noise.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file webex_handler-2.0.0.tar.gz.
File metadata
- Download URL: webex_handler-2.0.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c422d4fcdc18c73cd2ac8202751e661914c8fc083c33be8729cca26a45eaa9f7
|
|
| MD5 |
371f5042465a9bf9666f40c70b367b50
|
|
| BLAKE2b-256 |
0bcaa868d07dbbaead4db8bda28a6b9fd653f1638aab05dab044d495e05608c0
|
File details
Details for the file webex_handler-2.0.0-py3-none-any.whl.
File metadata
- Download URL: webex_handler-2.0.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa22317f0f549b70be23b912ba13446293404214e4ade68c01544a3f332310c9
|
|
| MD5 |
7e971e2f02362ce2ee5c37cf1713c54b
|
|
| BLAKE2b-256 |
0cc0d923fe0cae69f24b8f0aa4b6826c97ea641d088419a2868a71a4e80a4892
|