zoukankan      html  css  js  c++  java
  • 封装不同的打印

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

    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"
    ", __FILE__, __func__, __LINE__, ##args)
    #define WARN(x, args...)   printf(ANSI_COLOR_YELLOW "WARN , %s,%s:%d  "x ANSI_COLOR_RESET"
    ", __FILE__, __func__, __LINE__, ##args)
    #define INFO(x, args...)   printf(ANSI_COLOR_CYAN   "INFO , %s,%s:%d  "x ANSI_COLOR_RESET"
    ", __FILE__, __func__, __LINE__, ##args)
    #define DEBUG(x, args...)  printf(ANSI_COLOR_GREEN  "DEBUG, %s,%s:%d  "x ANSI_COLOR_RESET"
    ", __FILE__, __func__, __LINE__, ##args)
    int main()
    {
        printf("hello 
    ");
        INFO("hello world");
        ERROR("hello world");
        DEBUG("hello world");
        WARN("hello world");
        return 0;
    }

    运行结果

  • 相关阅读:
    php第九节课
    php第八节课
    php第七节课
    php第六讲
    php第五节课
    php第四节课
    php第三节课
    Golang Slice切片
    Golang 反射
    Golang 流程控制
  • 原文地址:https://www.cnblogs.com/doitjust/p/13933522.html
Copyright © 2011-2022 走看看