Skip to main content

py-color-log

python 颜色缤纷的日志


运行环境

介绍

封装了 colorlog 使其更易用,效果如图:

其特点为:

  • 默认的各等级颜色分配
  • 默认的日志滚动配置(按天滚动,最多保留 7 天)
  • 默认的第三方日志禁用:
    • requests
    • chardet.charsetprober
  • 灵活可控的配置

使用说明

在代码中引入 py-color-log 包即可:

from color_log.clog import log

log.debug('这是 DEBUG 日志,白色')
log.info('这是 INFO 日志,青绿')
log.warn('这是 WARN 日志,黄色')
log.error('这是 ERROR 日志,紫色')
try :
    a = 1 / 0
except :
    log.critical('这是 CRITICAL 日志,红色')

可以通过构造函数调整日志配置:

from color_log.clog import ColorLog

'''
[param] log_dir: 日志输出目录
[param] app_logs: 应用运行日志的名称字典,格式如 { name: min_level, ... }
[param] logfile_format: 输出日志文件的格式
[param] date_format: 输出日志文件的时间格式
[param] logcolors: 日志每个等级的颜色字典,格式如 { level: color, ... }
[param] rollday: 日志滚动间隔(单位:天)
[param] backupdays: 备份日志时长(单位:天)
[param] encoding: 日志编码
[param] debug: 是否打印 debug 日志
[param] thirdlist: 禁用的第三方日志列表
'''
log = ColorLog(
    log_dir = './logs', 
    app_logs = {
        'run.log': logging.INFO, 
        'err.log': logging.ERROR
    }, 
    logfile_format = '%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] - %(message)s', 
    date_format = '%Y-%m-%d %H:%M:%S', 
    log_colors = {
        'DEBUG': 'white',
        'INFO': 'cyan',
        'WARNING': 'yellow',
        'ERROR': 'purple',
        'CRITICAL': 'red',
    }, 
    rollday = 1, 
    backupdays = 7, 
    encoding = 'utf-8', 
    debug = True, 
    thirdlist = [ 
        'requests', 
        'chardet.charsetprober'
    ]
)

关于测试

详见 单元测试说明

赞助途径

支付宝 微信

版权声明

 Copyright (C) EXP,2016 License: GPL v3

Metadata

Release files for py-color-log 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-color-log 1.0.4
File Size Uploaded
py-color-log-1.0.4.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-color-log 1.0.4
File Interpreter ABI Platform
py_color_log-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / py-color-log-1.0.4.tar.gz

Download URL py-color-log-1.0.4.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fbe6afa214215b0f92fbb696afcb398f12f8b8bb1b3e0888d181df483ccaf13d
BLAKE2b-256 checksum
How to use checksums
828d4362bbfa62ad46d2e225b82f470f69d1716f00efc3ae5b4f2d8409f6f1c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / py_color_log-1.0.4-py3-none-any.whl

Download URL py_color_log-1.0.4-py3-none-any.whl
Size 6.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
811f70991f8a596d38a6bb5b1ea4456ccf28adf30cb510f8dd1f03280919f42d
BLAKE2b-256 checksum
How to use checksums
ba3df3f007151b2265ac61d847c944dad247793c294263919dd1eadc15061697
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page