亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有一個記錄日志的函數,想用宏定義進行包裝,簡化調用方法,但是xlc報如下的錯誤:

有一個記錄日志的函數,想用宏定義進行包裝,簡化調用方法,但是xlc報如下的錯誤:

C
一只名叫tom的貓 2023-04-25 20:16:37
void _log(const int level, char* file, int line, const char* fmt, ...){ va_list ap; int count; time_t t; struct tm* st; char str_time[255]; memset(str_time, 0x00, sizeof(str_time)); time(&t); st= localtime(&t); switch(level){ case DEBUG: fprintf(stdout, "[DEBUG] "); break; case INFO: fprintf(stdout, "[INFO] "); break; case WARNING: fprintf(stdout, "[WARNING] "); break; case ERROR: fprintf(stdout, "[ERROR] "); break; default: fprintf(stdout, "[INFO] "); break; } strftime( str_time, sizeof(str_time), "%Y-%m-%d %H:%M:%S", st); fprintf(stdout, "[%s] LINE:[%04d] [%s] ", file, line, str_time); va_start(ap, fmt); count = vfprintf(stdout, fmt, ap); fprintf(stdout, "\n"); fflush(stdout); va_end(ap); }#define log_info(...) _log((INFO), (__FILE__), (__LINE__), "", (#__VA_ARGS__))#define log_err(...) _log((ERROR), (__FILE__), (__LINE__), "", (#__VA_ARGS__))Syntax error at line 71, column 18, file RProCrminfo.cp:Error at line 71, column 18 in file RProCrminfo.cpdefine log_info((aaa), ...) _log((INFO), (__FILE__), (__LINE__), "", (#__VA_ARGS__)).................1PCC-S-02014, Encountered the symbol "(" when expecting one of the following:) ... an identifier, define, elif, else, endif, error, if,ifdef, ifndef, include, line, pragma, undef, exec, sql,begin, end, var, type, oracle,an immediate preprocessor command, a C token, create,function, package, procedure, trigger, or, replace,The symbol ")" was substituted for "(" to continue.
查看完整描述

1 回答

?
婷婷同學_

TA貢獻1844條經驗 獲得超8個贊

早先一個項目woj-land里用到的,供參考

#define FM_LOG_DEBUG(x...)   log_write(LOG_DEBUG, __FILE__, __LINE__, ##x)static void log_write(int level, const char *file,        const int line, const char *fmt, ...){    if (log_opened == 0)
    {        fprintf(stderr, "log_open not called yet\n");        exit(1);
    }    static char buffer[log_buffer_size];    static char datetime[100];    static char line_str[20];    static time_t now;
    now = time(NULL);    strftime(datetime, 99, "%Y-%m-%d %H:%M:%S", localtime(&now));    snprintf(line_str, 19, "%d", line);
    va_list ap;    va_start(ap, fmt);   
    vsnprintf(log_buffer, log_buffer_size, fmt, ap);   
    va_end(ap);   

    size_t count = snprintf(buffer, log_buffer_size,            "%s\x7 [%s]\x7 [%s:%d]%s\x7 %s\x7\n", 
            LOG_LEVEL_NOTE[level], datetime, file, line, log_extra_info, log_buffer);    int log_fd = log_fp->_fileno;    //puts(buffer);
    if (flock(log_fd, LOCK_EX) == 0)
    {        if (write(log_fd, buffer, count) < 0)
        {            perror("write error");            exit(1);
        }        flock(log_fd, LOCK_UN);
    }    else
    {        perror("flock error");        exit(1);
    }
}
查看完整回答
反對 回復 2023-04-28
  • 1 回答
  • 0 關注
  • 246 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號