Exemple #1
0
void debug_vprintf(int level, const char* fmt, va_list ap)
{
	if (-1 == debug_level) {

		char* str = getenv("DEBUG_LEVEL");
		debug_level = (NULL != str) ? atoi(str) : DP_INFO;
	}

	if (level <= debug_level) {

		FILE* ofp = (level < DP_INFO) ? stderr : stdout;

		if (debug_logging) {

			char dt_str[STRSIZE];
			get_datetime_str(STRSIZE, dt_str);

			fprintf(ofp, "[%s] [%s] - ", dt_str, get_level_str(level));

		} else
		if (level < DP_INFO)
			fprintf(ofp, "%s%s: ", (level < DP_INFO ? RED : ""), get_level_str(level));

		vfprintf(ofp, fmt, ap);

		if ((!debug_logging) && (level < DP_INFO))
			fprintf(ofp, RESET);

		fflush(ofp);
	}
}
void debug_vprintf(int level, const char* fmt, va_list ap)
{
	if (-1 == debug_level) {

		char* str = getenv("DEBUG_LEVEL");
		debug_level = (NULL != str) ? atoi(str) : DP_INFO;
	}

	if (level <= debug_level) {

		FILE* ofp = (level < DP_INFO) ? stderr : stdout;

		if (true == debug_logging) {

			char level_str[STRSIZE];
			char dt_str[STRSIZE];

			fprintf(ofp, "[%s] [%s] - ", get_datetime_str(dt_str), get_level_str(level, level_str));
		}

		vfprintf(ofp, fmt, ap);
		fflush(ofp);
	}
}