Skip to main content

基于loguru的高性能日志库

Project description

xtlog

基于 loguru 的高性能日志库

特性

  • 🚀 高性能: 基于 loguru 的高性能日志记录
  • 📝 双输出: 文件和控制台双输出支持
  • 🔄 自动轮转: 自动日志文件轮转和保留
  • 🎯 单例模式: 确保全局只有一个日志实例
  • 📍 智能定位: 自动识别调用位置信息
  • ⚙️ 动态配置: 支持动态设置日志级别
  • 🎨 丰富图标: 支持丰富的日志图标显示

安装

pip install xtlog

快速开始

from xtlog import mylog

# 基本使用
mylog.info("这是一条信息日志")
mylog.error("这是一条错误日志")

# 支持直接调用
mylog("第一条日志", "第二条日志")

# 设置日志级别
mylog.set_level("DEBUG")

高级功能

自定义日志配置

from xtlog import LogCls

# 创建自定义日志实例
custom_log = LogCls(
    level=20,  # INFO级别
    log_file_rotation_size="10 MB",
    log_file_retention_days="7 days"
)

custom_log.info("自定义配置的日志")

使用 callfrom 参数

from xtlog import mylog

def my_function():
    mylog.info("函数内的日志", callfrom=my_function)

my_function()

日志级别

支持以下日志级别:

  • TRACE (5)
  • DEBUG (10)
  • INFO (20)
  • SUCCESS (25)
  • WARNING (30)
  • ERROR (40)
  • CRITICAL (50)

配置

环境变量

  • ENV: 设置环境类型,dev 为开发环境(显示控制台日志),其他为生产环境

默认配置

  • 日志文件位置: 项目根目录/logs/xt_YYYYMMDD.log
  • 文件轮转大小: 16 MB
  • 文件保留天数: 30 days
  • 默认日志级别: DEBUG (10)

开发

安装开发依赖

pip install -e .[dev]

代码检查

ruff check --fix --unsafe-fixes

类型检查

mypy .

许可证

MIT License

作者

sandorn sandorn@live.cn

GitHub: http://github.com/sandorn/xtlog

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

xtlog-0.1.0.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xtlog-0.1.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file xtlog-0.1.0.tar.gz.

File metadata

  • Download URL: xtlog-0.1.0.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for xtlog-0.1.0.tar.gz
Algorithm Hash digest
SHA256 52d0b41fbfb025c9966b424adb92f45059d659e323a51471ed42cb9f0a714647
MD5 d91201c229e2e4b706926ce113dea3b9
BLAKE2b-256 0782065d97688e98350497a5dd19e984df6699f0765779b16bebadcc565ae318

See more details on using hashes here.

File details

Details for the file xtlog-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: xtlog-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for xtlog-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43c0886fb4ac002a1ca7e0f5cec4333a99097f1d8079aba70f8c498deca9cd14
MD5 260c315eb295a9d2e6860562d70bb9fb
BLAKE2b-256 c94c4028cae07d444ed80548cad11574cd2b7c615aa89457217729598cb09917

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page