int zc_profile_inner(int flag, const char *file, const long line, const char *fmt, ...) { va_list args; char time_str[20 + 1]; FILE *fp = NULL; static char *debug_log = NULL; static char *error_log = NULL; static size_t init_flag = 0; if (!init_flag) { init_flag = 1; debug_log = getenv("ZLOG_PROFILE_DEBUG"); error_log = getenv("ZLOG_PROFILE_ERROR"); } switch (flag) { case ZC_DEBUG: if (debug_log == NULL) return 0; fp = fopen(debug_log, "a"); if (!fp) return -1; zc_time(time_str, sizeof(time_str)); fprintf(fp, "%s DEBUG (%d:%s:%ld) ", time_str, getpid(), file, line); break; case ZC_WARN: if (error_log == NULL) return 0; fp = fopen(error_log, "a"); if (!fp) return -1; zc_time(time_str, sizeof(time_str)); fprintf(fp, "%s WARN (%d:%s:%ld) ", time_str, getpid(), file, line); break; case ZC_ERROR: if (error_log == NULL) return 0; fp = fopen(error_log, "a"); if (!fp) return -1; zc_time(time_str, sizeof(time_str)); fprintf(fp, "%s ERROR (%d:%s:%ld) ", time_str, getpid(), file, line); break; } /* writing file twice(time & msg) is not atomic * may cause cross * but avoid log size limit */ va_start(args, fmt); vfprintf(fp, fmt, args); va_end(args); fprintf(fp, "\n"); fclose(fp); return 0; }
int zc_profile_inner(int flag, const char *file, const long line, const char *fmt, ...) { char time_str[20 + 1]; int x; int y; switch (flag) { case ZC_DEBUG: x = 1; zc_time(time_str); y = 1; break; case ZC_WARN: x = 2; zc_time(time_str); y = 2; break; } return 0; }