打印等級的控制

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

int gDbPrintf(int level, const char *file, const char *func, int line, const char *fmt,...)
{
    char printf_buf[1024];
    va_list args;
    int printed;
    if(level >= 1)
    {
        return 0;
    }
    va_start(args, fmt);
    printed = vsprintf(printf_buf, fmt, args);
    va_end(args);
    printf("[%s:%s:%d] ",file,func,line);
    printf("%s",printf_buf);
    return printed;
}

#define DB_ERROR(fmt...) gDbPrintf(0,__FILE__,__FUNCTION__,__LINE__,fmt)

int main(int a,char *b[])
{
    DB_ERROR("dtcwyp:a=%d,%s,%s\n",a,b[0],b[1]);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章