Skip to main content

Printing and debugging with color

Project description

cprintf

安装

pip install cprintf

使用方法

import cprintf
from time import sleep

# 设置日志级别
cprintf.set_log_level('DEBUG')  # 可选: DEBUG, INFO, WARNING, ERROR, FATAL

# 基本打印功能
cprintf.info("普通字符串")
cprintf.info('{"hello": "world", "list": [1, 2, 3]}')
cprintf.info({"hello": "world", "list": [1, 2, 3]})
cprintf.warn({"warn_key": True})
cprintf.err("这是一条错误信息", format_mode='pprint')
cprintf.fatal("This is a fatal error.")
cprintf.ok('强制使用 pprint 模式', format_mode='pprint')
cprintf.debug('强制使用 raw 模式', format_mode='raw')

# 带时间戳的日志
cprintf.info("这是一条带时间戳的信息", timestamp=True)

# 分割线
cprintf.line()
cprintf.line(char='=', length=60, color='OK')

# 自定义颜色
cprintf.custom("This is a custom color message in cyan!", "\033[96m")

# 进度条
for i in range(100):
    sleep(0.1)
    cprintf.progress_bar(i + 1, 100, prefix='进度:', suffix='完成', length=50)

# 打印表格
data = [
    [1, "Alice", 25],
    [2, "Bob", 30],
    [3, "Charlie", 35]
]
cprintf.print_table(data, headers=["ID", "Name", "Age"], color='INFO')

# 获取带颜色的字符串(不打印)
colored_str = cprintf.get_colored_string("这是一个带颜色的字符串", color='WARNING')
print(colored_str)

功能说明

  • 日志级别控制:通过 set_log_level() 设置日志级别,低于该级别的日志将不会显示
  • 时间戳:在日志信息前添加时间戳,使用 timestamp=True 参数
  • 进度条:使用 progress_bar() 方法显示进度条
  • 表格打印:使用 print_table() 方法打印整齐的表格
  • 自定义颜色:使用 custom() 方法自定义颜色,或使用 get_colored_string() 获取带颜色的字符串
  • 格式化模式:支持 rawjsonpprintauto 四种格式化模式

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

cprintf-0.0.8.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

cprintf-0.0.8-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file cprintf-0.0.8.tar.gz.

File metadata

  • Download URL: cprintf-0.0.8.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.0

File hashes

Hashes for cprintf-0.0.8.tar.gz
Algorithm Hash digest
SHA256 30fdd3b16ca12ec31ab187d3caa3c18f2b16d99ceb729999d50175da76b72781
MD5 79c5a14865edf38f656146fa69755865
BLAKE2b-256 53c1811a0f2b6bc9a78cd77e6189c8495e814c6879a2239e62534c7f6ef2e8fd

See more details on using hashes here.

File details

Details for the file cprintf-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: cprintf-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.0

File hashes

Hashes for cprintf-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a7c11193c1422319b875d0a1ec06dd6c92fb0cd0651c042643e0debbe4d8c18c
MD5 7af5870eee7939af63368dc30cc189c9
BLAKE2b-256 1ae44bf484c4131a3be549cd22b86f99d5a32e1035af7dee2cca1df03573634a

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