如何使用1行代码让你的C 程序控制台输出彩色log信息

本文介绍了如何使用colorwheel库通过一行代码让C++程序的控制台输出带有颜色的log信息,包括安装、使用方法,以及相关的宏定义和代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文首发于个人博客https://kezunlin.me/post/a201e11b/,欢迎阅读最新内容!

colorwheel for colored print and trace for cpp programs

Guide

install

    sudo wget -O /usr/include/colorwheel.h https://raw.githubusercontent.com/Totoditoto/colorwheel/master/colorwheel.h
> /usr/include/colorwheel.h

usage

only include header

    #include <colorwheel.h>

macros

    /* Predefined printf styled messages */
    CW_PRINT_NORMAL(message, ...);
    CW_PRINT_ALARM(message, ...);
    CW_PRINT_CRITICAL(message, ...);
    CW_PRINT_FAULT(message, ...);
    CW_PRINT_VALID(message, ...);
    CW_PRINT_INFO(message, ...);
    /* Predefined trace styled messages (indicates file, function and line) */
    CW_TRACE_NORMAL(message, ...);
    CW_TRACE_ALARM(message, ...);
    CW_TRACE_CRITICAL(message, ...);
    CW_TRACE_FAULT(message, ...);
    CW_TRACE_VALID(message, ...);
    CW_TRACE_INFO(message, ...);

code

#include <colorwheel.h>

void demo_colorwheel(void)
{
    CW_TRACE_NORMAL("This is a normal information");
    CW_TRACE_INFO("This is a noticeable information");
    CW_TRACE_FAULT("Ooops something might have gone wrong");
    CW_TRACE_VALID("Finally it's okay, don't worry");
    //CW_TRACE_NORMAL("Nevermind");
    int value = 10;
    CW_TRACE_CRITICAL("It was way worse than expected! Computer will explode in %d s", value);
    CW_TRACE_ALARM("IT IS TOO LATE RUN AWAY");
}

colored print

Reference

History

  • 20191010: created.

Copyright

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值