Skip to main content

LingHu - 智能化工具包

Project description

LingHu

一个功能强大的Python工具包,提供日志记录、基础功能封装等实用工具。

功能特性

  • 📝 灵活的日志系统 - 支持自定义路径、文件名、日志轮转和控制台输出
  • 🔧 基础功能封装 - 提供常用功能的统一接口
  • 🚀 高性能 - 采用单例模式,线程安全
  • 📦 易于使用 - 简洁的API设计,快速上手

安装

pip install -r requirements.txt

日志模块使用指南

基础配置

from LingHu import setup_logging

# 基础配置
setup_logging(
    log_dir="./logs",           # 日志目录
    log_filename="app.log",     # 日志文件名
    log_level="INFO",           # 日志级别
    console_output=True,        # 控制台输出
    file_output=True            # 文件输出
)

高级配置

from LingHu import configure_logging

# 高级配置
configure_logging(
    max_file_size=20*1024*1024, # 20MB
    backup_count=10,            # 10个备份
    format_string="%(asctime)s [%(levelname)s] %(message)s",
    date_format="%Y-%m-%d %H:%M:%S"
)

使用Logger类

from LingHu import Logger

# 创建日志器实例
logger = Logger(
    log_dir="./my_logs",
    log_filename="custom.log",
    log_level="DEBUG"
)

# 使用日志功能
logger.debug("这是一条调试信息")
logger.info("这是一条普通信息")
logger.warning("这是一条警告信息")
logger.error("这是一条错误信息")
logger.critical("这是一条严重错误信息")

快捷函数使用

from LingHu import debug, info, warning, error, critical

# 直接使用快捷函数
info("程序启动成功")
debug("调试信息:变量值 = %s", some_variable)
warning("检测到潜在问题")
error("操作失败")
critical("系统严重错误")

与Base类结合使用

from LingHu import Base, Logger

# 创建带有日志功能的Base实例
base = Base()
logger = Logger()

# 在业务逻辑中使用日志
result = base.user_login()
if result:
    logger.info("用户登录成功")
else:
    logger.error("用户登录失败")

配置选项说明

参数 类型 默认值 说明
log_dir str "./logs" 日志文件目录
log_filename str 自动生成 日志文件名
log_level str/int "INFO" 日志级别 (DEBUG, INFO, WARNING, ERROR, CRITICAL)
max_file_size int 10MB 单个日志文件最大大小
backup_count int 5 保留的备份文件数量
console_output bool True 是否输出到控制台
file_output bool True 是否输出到文件
format_string str 默认格式 日志格式字符串
date_format str "%Y-%m-%d %H:%M:%S" 日期格式字符串

日志级别说明

  • DEBUG: 详细的调试信息,通常只在开发时使用
  • INFO: 一般信息,确认程序按预期运行
  • WARNING: 警告信息,表示可能的问题
  • ERROR: 错误信息,程序遇到问题但能继续运行
  • CRITICAL: 严重错误,程序可能无法继续运行

项目结构

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

linghu-1.0.0-cp313-cp313-manylinux1_x86_64.whl (72.1 MB view details)

Uploaded CPython 3.13

File details

Details for the file linghu-1.0.0-cp313-cp313-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for linghu-1.0.0-cp313-cp313-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 174894e430bccac2c1191dbc4dd4abc1a2eea43438035197a86a85f120224622
MD5 b03eaadce1eb556648f59d1e5b4f2042
BLAKE2b-256 01e0a33ede1fe1b5b28060e592a063103408824c5de7cbee5d87dbf7abf7c3a5

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