Skip to main content

python color log

Project description

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

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

py-color-log-1.0.4.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

py_color_log-1.0.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file py-color-log-1.0.4.tar.gz.

File metadata

  • Download URL: py-color-log-1.0.4.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for py-color-log-1.0.4.tar.gz
Algorithm Hash digest
SHA256 fbe6afa214215b0f92fbb696afcb398f12f8b8bb1b3e0888d181df483ccaf13d
MD5 13945e2fa7d2073e3ab0c59022038efa
BLAKE2b-256 828d4362bbfa62ad46d2e225b82f470f69d1716f00efc3ae5b4f2d8409f6f1c5

See more details on using hashes here.

File details

Details for the file py_color_log-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for py_color_log-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 811f70991f8a596d38a6bb5b1ea4456ccf28adf30cb510f8dd1f03280919f42d
MD5 d233ba5510d1e51d60cf6fe067d6a96b
BLAKE2b-256 ba3df3f007151b2265ac61d847c944dad247793c294263919dd1eadc15061697

See more details on using hashes here.

Supported by

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