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
Hashes for webex_handler-2.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa22317f0f549b70be23b912ba13446293404214e4ade68c01544a3f332310c9 |
|
MD5 | 7e971e2f02362ce2ee5c37cf1713c54b |
|
BLAKE2b-256 | 0cc0d923fe0cae69f24b8f0aa4b6826c97ea641d088419a2868a71a4e80a4892 |