C利用宏定义LOG打印思路

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>


#define LOGD(format, args...)  log_debug(format, ##args, __FILE__, __LINE__)
void log_debug(char* p,...)
{
    char buf[256] = {0};
    va_list list;
    va_start(list, p);
    vsprintf(buf, p, list);
    printf("%s", buf);
    va_end(list);
}

int main()
{
    LOGD("test %s \n","abc");
    LOGD("test xxxx\n");
    return 0;
}

猜你喜欢

转载自blog.csdn.net/PZ0605/article/details/107363937