企业级 Loguru Sink 工厂,基于 loguru-config 的简洁架构,专注于阿里云 SLS 支持
Project description
yai-loguru-sinks
企业级 Loguru Sink 工厂库,基于 loguru-config 提供统一的配置驱动体验。
核心理念
- 简洁架构:移除复杂的插件抽象,直接提供 sink 工厂函数
- 配置驱动:基于
loguru-config的统一配置体验 - 企业级:专注于阿里云 SLS 日志服务
- 原生兼容:完全兼容 Loguru 的 sink 机制
快速开始
安装
uv add yai-loguru-sinks
基本使用
from yai_loguru_sinks import setup_extended_config
from loguru_config import LoguruConfig
# 注册企业级协议解析器
setup_extended_config()
# 配置驱动,一行搞定
config = LoguruConfig()
config.load('logging.yaml')
配置文件示例
# logging.yaml
handlers:
# 阿里云 SLS
- sink: sls://my-project/my-logstore?region=cn-hangzhou&access_key_id=${SLS_ACCESS_KEY}&access_key_secret=${SLS_SECRET}
level: WARNING
format: '{time} | {level} | {message}'
# 本地文件(Loguru 原生)
- sink: logs/app.log
rotation: "1 day"
retention: "30 days"
compression: "gz"
支持的 Sink 类型
阿里云 SLS
sink: sls://project/logstore?region=cn-hangzhou&access_key_id=xxx&access_key_secret=xxx
直接使用 Sink 工厂
如果不使用配置文件,也可以直接调用 sink 工厂:
from loguru import logger
from yai_loguru_sinks.sls import create_sls_sink
# 创建 SLS sink
sls_sink = create_sls_sink(
project="my-project",
logstore="my-logstore",
region="cn-hangzhou",
access_key_id="xxx",
access_key_secret="xxx"
)
# 添加到 logger
logger.add(sls_sink, level="WARNING")
架构优势
相比传统插件系统
- ✅ 移除冗余抽象:不再需要
LoguruPlugin基类 - ✅ 简化使用方式:统一的配置文件格式
- ✅ 利用成熟生态:基于
loguru-config的稳定基础 - ✅ 保持功能完整:所有企业级功能都保留
设计原则
- 职责分离:
loguru负责基础功能,yai-loguru-sinks负责企业级扩展 - 配置驱动:通过 YAML/JSON 配置,而非代码硬编码
- 协议扩展:利用
loguru-config的协议解析机制 - 工厂模式:提供灵活的 sink 创建函数
许可证
MIT License
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
yai_loguru_sinks-0.5.1.tar.gz
(100.5 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 yai_loguru_sinks-0.5.1.tar.gz.
File metadata
- Download URL: yai_loguru_sinks-0.5.1.tar.gz
- Upload date:
- Size: 100.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cb5b02f2b17183950a36e236784787ad95700de3ef1f89dbb97f64640c614eb
|
|
| MD5 |
1453959cbec4856b7b2a100c8ec64ddd
|
|
| BLAKE2b-256 |
3964a0197c93a00057bb38a2ac9f5d7bde1ccb47313aa48edbded4087e95bdd4
|
File details
Details for the file yai_loguru_sinks-0.5.1-py3-none-any.whl.
File metadata
- Download URL: yai_loguru_sinks-0.5.1-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0f28c7387feee936250de6f6f0652afa6ef020bf4094129f6f0c488eaf8d4ba
|
|
| MD5 |
19328b48f9a6d0d08a7baa765772cd43
|
|
| BLAKE2b-256 |
74386424820e37e7802c05a30582e2f84076c7be1516472ec5118f3d01f5de56
|