一个支持 异步、批量、重试、多通道通知 的 logging 扩展库。
Project description
pylogging-ext
一个支持 异步、批量、重试、多通道通知 的 logging 扩展库。
不只是 logging handler
安装
pip install pylogging-ext
可选依赖
- cls:腾讯云 CLS 支持
pip install pylogging_ext[cls]
- socks:SOCKS 代理支持
pip install pylogging_ext[socks]
使用
import logging
from pylogging_ext import TelegramHandler
logger = logging.getLogger('demo')
logger.setLevel(logging.INFO)
handler = TelegramHandler(
token='your-bot-token',
chat_id='your-chat-id',
)
logger.addHandler(handler)
logger.error('发生错误了')
API
Class: BaseHandler
通用异步 Handler 基类,所有通知 Handler 均继承自此类。
BaseHandler(...)
batch_size批量发送大小flush_interval刷新间隔 (秒)queue_size队列大小retry重试次数
特性:
- 异步发送(非阻塞)
- 批量处理
- 指数退避重试
- 优雅关闭
腾讯云 CLS
Class: TencentCloudCLSHandler
from pylogging_ext import TencentCloudCLSHandler
handler = TencentCloudCLSHandler(
endpoint='ap-shanghai.cls.tencentcs.com',
secret_id='your-secret-id',
secret_key='your-secret-key',
topic_id='your-topic-id',
)
参数
endpointCLS接入地址secret_id腾讯云密钥secret_key腾讯云密钥topic_id日志主题 ID
微信机器人
Class: WeChatHandler
from pylogging_ext import WeChatHandler
handler = WeChatHandler(
webhook='https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxx'
)
参数
webhook企业微信机器人地址
Telegram
Class: TelegramHandler
from pylogging_ext import TelegramHandler
handler = TelegramHandler(
token='your-bot-token',
chat_id='your-chat-id',
proxies={
'http': 'http://127.0.0.1:7890',
'https': 'http://127.0.0.1:7890',
}
)
参数
tokenTelegram Bot Tokenchat_id聊天 IDproxies代理配置(可选)ssl_verifySSL校验 (默认 True)
钉钉机器人
Class: DingTalkHandler
from pylogging_ext import DingTalkHandler
handler = DingTalkHandler(
access_token='your-access-token',
secret='your-secret',
at_mobiles=['18600000000'],
)
参数
access_tokenWebhook URL 中的 access_tokensecret签名密钥(开启加签时必填)at_mobiles被@人的手机号(可选)is_at_all@所有人是 True,否则为 False (默认 False)
飞书机器人
Class: FeiShuHandler
from pylogging_ext import FeiShuHandler
handler = FeiShuHandler(
webhook='https://open.feishu.cn/open-apis/bot/v2/hook/xxx',
secret='your-secret',
at_users=['ou_18eac8********17ad4f02e8bbbb']
)
参数
webhook飞书机器人地址secret签名密钥(开启加签时必填)at_users用户的 Open ID 或 User ID,@ 所有人时,填 all(可选)
支持的处理器
- 腾讯云 CLS
- 企业微信
- Telegram
- 钉钉
- 飞书
持续扩展中...
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
pylogging_ext-0.2.1.tar.gz
(11.4 kB
view details)
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 pylogging_ext-0.2.1.tar.gz.
File metadata
- Download URL: pylogging_ext-0.2.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d8cdcd4bb8e9724dfb84868f13b2561eed4f49eeeee7f7ad53f5b87d2a569a6
|
|
| MD5 |
735ad71ec520659cba16f34ee14d3ebc
|
|
| BLAKE2b-256 |
5742577854fed1d702d1f448efe669812f0f460fb5d4a7c770e89b61c25e0635
|
File details
Details for the file pylogging_ext-0.2.1-py3-none-any.whl.
File metadata
- Download URL: pylogging_ext-0.2.1-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a3d9571ec30131f229ea37a65c7b479f86eaf3375dc391c6821a5392d70718f
|
|
| MD5 |
090551bd1e3c0bb24d146bc4a4b5f56c
|
|
| BLAKE2b-256 |
0e49c6b5c2ba5c481e9ef64c8b3e8464edb8e1386c8d1d8f8ac2f3df3a9e827c
|