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
- 钉钉
- 飞书
持续扩展中...
Metadata
Release files for pylogging-ext 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pylogging_ext-0.2.1.tar.gz | 11.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pylogging_ext-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.9 kB
Release files / pylogging_ext-0.2.1.tar.gz
| Download URL | pylogging_ext-0.2.1.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d8cdcd4bb8e9724dfb84868f13b2561eed4f49eeeee7f7ad53f5b87d2a569a6
|
|
BLAKE2b-256 checksum How to use checksums |
5742577854fed1d702d1f448efe669812f0f460fb5d4a7c770e89b61c25e0635
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / pylogging_ext-0.2.1-py3-none-any.whl
| Download URL | pylogging_ext-0.2.1-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a3d9571ec30131f229ea37a65c7b479f86eaf3375dc391c6821a5392d70718f
|
|
BLAKE2b-256 checksum How to use checksums |
0e49c6b5c2ba5c481e9ef64c8b3e8464edb8e1386c8d1d8f8ac2f3df3a9e827c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for pylogging-ext 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.