码迷,mamicode.com
首页 > 其他好文 > 详细

封装不同的打印

时间:2020-11-06 02:32:36      阅读:17      评论:0      收藏:0      [点我收藏+]

标签:__file__   颜色   ima   rgba   bsp   res   world   http   alt   

 

封装打印,区分颜色,显示文件名,函数名和行号

01_test_printf.c

#include <stdio.h>
#define ANSI_COLOR_RED     "\x1b[31m"
#define ANSI_COLOR_GREEN   "\x1b[32m"
#define ANSI_COLOR_YELLOW  "\x1b[33m"
#define ANSI_COLOR_BLUE    "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN    "\x1b[36m"
#define ANSI_COLOR_RESET   "\x1b[0m"

#define ERROR(x, args...)  printf(ANSI_COLOR_RED    "ERROR, %s,%s:%d  "x ANSI_COLOR_RESET"\n", __FILE__, __func__, __LINE__, ##args)
#define WARN(x, args...)   printf(ANSI_COLOR_YELLOW "WARN , %s,%s:%d  "x ANSI_COLOR_RESET"\n", __FILE__, __func__, __LINE__, ##args)
#define INFO(x, args...)   printf(ANSI_COLOR_CYAN   "INFO , %s,%s:%d  "x ANSI_COLOR_RESET"\n", __FILE__, __func__, __LINE__, ##args)
#define DEBUG(x, args...)  printf(ANSI_COLOR_GREEN  "DEBUG, %s,%s:%d  "x ANSI_COLOR_RESET"\n", __FILE__, __func__, __LINE__, ##args)
int main()
{
    printf("hello \n");
    INFO("hello world");
    ERROR("hello world");
    DEBUG("hello world");
    WARN("hello world");
    return 0;
}

运行结果

技术图片

 

封装不同的打印

标签:__file__   颜色   ima   rgba   bsp   res   world   http   alt   

原文地址:https://www.cnblogs.com/doitjust/p/13933522.html

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