C 调试LOG函数

来源:互联网 发布:钱复业知乎 编辑:程序博客网 时间:2024/05/08 00:53

#define web_LOG(fmt, rest...) websPrintLog(__FUNCTION__, __LINE__, fmt, ##rest)

int websPrintLog(char *fun, int line, char * str, ...)
{
 char buf[256]={0};
 sprintf(buf,"echo \" [%s<%d>] ",fun ,line);
 int len = strlen(buf);
 va_list ap;
 /*格式化输入字符串*/
 va_start(ap,str);
 vsnprintf(buf+len, sizeof(buf), str, ap);
 va_end(ap);
 strcat(buf,"\" >> /etc/web/log ");
 system(buf);
}

使用
web_LOG("test %d",1);

原创粉丝点击