码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2019-12-13 09:19:29      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:cat   notice   mac   trace   macro   lin   stat   form   arm   

本文首发于个人博客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");
}

技术图片

Reference

History

  • 20191010: created.

Copyright

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

标签:cat   notice   mac   trace   macro   lin   stat   form   arm   

原文地址:https://www.cnblogs.com/kezunlin/p/12033135.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!