{"id":23087634,"url":"https://github.com/exp-codes/py-color-log","last_synced_at":"2025-04-03T16:45:39.143Z","repository":{"id":61842222,"uuid":"454639484","full_name":"EXP-Codes/py-color-log","owner":"EXP-Codes","description":"python 彩色日志","archived":false,"fork":false,"pushed_at":"2023-01-16T17:52:40.000Z","size":265,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-03T00:56:34.844Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/py-color-log/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EXP-Codes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":["https://lyy289065406.github.io/sponsor/"]}},"created_at":"2022-02-02T04:13:38.000Z","updated_at":"2023-05-03T14:33:15.000Z","dependencies_parsed_at":"2023-02-10T05:16:11.541Z","dependency_job_id":null,"html_url":"https://github.com/EXP-Codes/py-color-log","commit_stats":null,"previous_names":["lyy289065406/py-color-log"],"tags_count":1,"template":false,"template_full_name":"EXP-Codes/pypi-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EXP-Codes%2Fpy-color-log","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EXP-Codes%2Fpy-color-log/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EXP-Codes%2Fpy-color-log/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EXP-Codes%2Fpy-color-log/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EXP-Codes","download_url":"https://codeload.github.com/EXP-Codes/py-color-log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247043221,"owners_count":20874084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T19:59:25.633Z","updated_at":"2025-04-03T16:45:39.123Z","avatar_url":"https://github.com/EXP-Codes.png","language":"Python","funding_links":["https://lyy289065406.github.io/sponsor/"],"categories":[],"sub_categories":[],"readme":"# py-color-log\n\n\u003e python 彩色日志\n\n------\n\n## 运行环境\n\n![](https://img.shields.io/badge/Python-3.8%2B-brightgreen.svg)\n\n\n## 介绍\n\n封装了 colorlog 使其更易用，效果如图：\n\n![](./imgs/01.png)\n\n其特点为：\n\n- 默认的各等级颜色分配\n- 默认的日志滚动配置（按天滚动，最多保留 7 天）\n- 默认的第三方日志禁用：\n    - `requests`\n    - `chardet.charsetprober`\n- 灵活可控的配置\n\n\n## 安装说明\n\n执行脚本： \n\n```\npython -m pip install --upgrade pip\npython -m pip install py-color-log\n```\n\n\n## 使用说明\n\n在代码中引入 py-color-log 包即可：\n\n```python\nfrom color_log.clog import log\n\nlog.debug('这是 DEBUG 日志，白色')\nlog.info('这是 INFO 日志，青绿')\nlog.warn('这是 WARN 日志，黄色')\nlog.error('这是 ERROR 日志，紫色')\ntry :\n    a = 1 / 0\nexcept :\n    log.critical('这是 CRITICAL 日志，红色')\n```\n\n可以通过构造函数调整日志配置：\n\n```python\nfrom color_log.clog import ColorLog\n\n'''\n[param] log_dir: 日志输出目录\n[param] app_logs: 应用运行日志的名称字典，格式如 { name: min_level, ... }\n[param] logfile_format: 输出日志文件的格式\n[param] date_format: 输出日志文件的时间格式\n[param] logcolors: 日志每个等级的颜色字典，格式如 { level: color, ... }\n[param] rollday: 日志滚动间隔（单位：天）\n[param] backupdays: 备份日志时长（单位：天）\n[param] encoding: 日志编码\n[param] debug: 是否打印 debug 日志\n[param] thirdlist: 禁用的第三方日志列表\n'''\nlog = ColorLog(\n    log_dir = './logs', \n    app_logs = {\n        'run.log': logging.INFO, \n        'err.log': logging.ERROR\n    }, \n    logfile_format = '%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] - %(message)s', \n    date_format = '%Y-%m-%d %H:%M:%S', \n    log_colors = {\n        'DEBUG': 'white',\n        'INFO': 'cyan',\n        'WARNING': 'yellow',\n        'ERROR': 'purple',\n        'CRITICAL': 'red',\n    }, \n    rollday = 1, \n    backupdays = 7, \n    encoding = 'utf-8', \n    debug = True, \n    thirdlist = [ \n        'requests', \n        'chardet.charsetprober'\n    ]\n)\n```\n\n### 关于测试\n\n详见 [单元测试说明](tests)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexp-codes%2Fpy-color-log","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexp-codes%2Fpy-color-log","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexp-codes%2Fpy-color-log/lists"}