logging的飞书handler
Project description
feishu-logging-handler
通过webhook将自定义服务的消息推送至飞书
更新记录
- 1.0.6 修复了bug、stack_info并且可以换行输出
- 1.0.5 增加stack_info的支持
- 1.0.5 增加了error不是str的支持(特别是try except的时候)
特点:
- 异步有可能会遇到loop已释放的问题,调整为同步。启用多线程,所以性能ok
- 增加缓存支持,重复消息设置一个时间周期,不会重复发送
- 支持 filter_key 来过滤部分error的key
安装
pip install feishu-logging-handler -i https://pypi.org/simple
配置
- 创建一个飞书群组
- 点击群设置,添加一个机器人,并生成Webhook地址
- 可以设置关键词过滤
使用方式
初始化:
from feishu_logging.handler import FeiShuWebhookHandler
log_feishu = logging.getLogger("feishu")
http_handler = FeiShuWebhookHandler("https://open.feishu.cn/open-apis/bot/v2/hook/xxx","key_word",cache_time=10,filter_key=["funcName","msg","levelname","args","pathname","lineno","threadName","stack_info"]) # cache_time = 0为不启用cache
http_handler.setLevel(logging.DEBUG)
log_feishu.addHandler(http_handler)
注意是否会初始化多次 addHandler 如果多次会请求多次
if not log_feishu.handlers:
http_handler = FeiShuWebhookHandler("https://open.feishu.cn/open-apis/bot/v2/hook/xxx","key_word",cache_time=10,filter_key=["funcName","msg","levelname","args","pathname","lineno","threadName","stack_info"]) # cache_time = 0为不启用cache
http_handler.setLevel(logging.DEBUG)
log_feishu.addHandler(http_handler)
写日志:
log_feishu = logging.getLogger("feishu")
log_feishu.error("错误测试")
填入Webhook地址和关键词(或项目名称)即可
Project details
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
File details
Details for the file feishu_logging_handler-1.0.6.tar.gz
.
File metadata
- Download URL: feishu_logging_handler-1.0.6.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6cff4654e4eb90766df12d7a83cb6e2df4be5a38be4b81a1f96497536afe55a |
|
MD5 | 68a79743b4a4e438784f43e777503b17 |
|
BLAKE2b-256 | 1afde8c627c405f1b5b505df7ae69637e5185a0519d2cf005ec3c8623bea49b1 |
File details
Details for the file feishu_logging_handler-1.0.6-py3-none-any.whl
.
File metadata
- Download URL: feishu_logging_handler-1.0.6-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e474a3afa4fb5f7a19d7b183599a6c792444a66a882d2f49f4cd63a7a086d52 |
|
MD5 | 67fedad4a13d62fd4a1dabdc73a4fe26 |
|
BLAKE2b-256 | 8ec998d8513753f79331f34fdf728e4526fa30e9c1def4bca628fa0a79a7fa50 |