Metadata-Version: 2.1
Name: mlogs
Version: 0.2.2
Summary: loguru packaging log tools
Home-page: UNKNOWN
Author: Caturbhuja
Author-email: caturbhuja@foxmail.com
License: MIT
Platform: UNKNOWN
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Description-Content-Type: text/markdown

### 简介
loguru 基础上封装的 开箱即用的 python 日志 工具包   
loguru https://loguru.readthedocs.io/en/stable/overview.html#installation   
notifiers https://notifiers.readthedocs.io/en/latest/usage.html#provider-schema   

### 使用方法  
```shell  
pip install mlogs
```

```python
from mlogs import MLogger
L = MLogger()
L.info("nice")

# trace_id 可以用来 链路追踪， topic 用于分类
L.warning("nice", trace_id="12312321", topic="model:task")
L.warning({"msg": "nice", "gg_monkey": "bugs"}, trace_id="12312321", topic="model:task")

# MLogger 会同时输出日志到 terminal 日志文件
# FileLogger   仅输出日志到 日志文件，按照日志级别生成 不同的日志文件
# StdoutLogger 仅输出日志到 terminal
# AdaptHistoryLogger 为了兼容历史项目日志


# 配置邮件接收 （release 0.1.3）
"""
email 发送邮件，使用的是python 原生库 smtplib.SMTP
"""
from mlogs import StdoutLogger

alerts = {
    "alerts_type": "email",
    "params": {
        "username": "username",
        "password": "password",
        "host": "smtp.exmail.qq.com",  # 邮箱服务器地址
        "port": 465,  # 邮箱服务器端口
        "from": "yourname@cc.com",  # 邮件发送人
        "to": [
            "yourname@cc.com",  # 邮件接收人
        ],
        "login": True,
        "ssl": True,    # 绝大多数邮箱，均开启了ssl服务，所以需要配置
    },
}

L = StdoutLogger(alerts=alerts)
L.error('nice')


# default topic （release 0.2.0）
"""
当一个项目里面包含多个服务时，需要使用topic来区分，那么可以在日志初始化时，统一设置default topic。
"""
from mlogs import StdoutLogger

L1 = StdoutLogger(default_topic="1")
L2 = StdoutLogger(default_topic="2")
L3 = StdoutLogger(default_topic="3")

L1.info('nice')
L2.info('nice')
L3.info('nice', topic="333")

```

### 一些介绍
1. FileLogger 默认按照 50 MB分割文件，最多储存 10 个文件，默认不压缩日志。  
2. 日志级别默认为DEBUG，可以自定义设置，也可以使用环境变量 export DEPLOYMENT=PRODUCTION，设置日志级别为 INFO

### 版本更新内容

    0.2.0 新增 default topic，在类初始化时设置，则后续所有日志会添加此 topic  
    0.1.3 新增 邮件发送配置  
    0.0.10 项目开始  


