#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);