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); } }
- 1 回答
- 0 关注
- 192 浏览
添加回答
举报
0/150
提交
取消