Skip to content
Snippets Groups Projects
elog.c 50.8 KiB
Newer Older
 *	Append the string to the StringInfo buffer, inserting a tab after any
 *	newline.
static void
append_with_tabs(StringInfo buf, const char *str)
Bruce Momjian's avatar
Bruce Momjian committed
	char		ch;
	while ((ch = *str++) != '\0')
		appendStringInfoCharMacro(buf, ch);
		if (ch == '\n')
			appendStringInfoCharMacro(buf, '\t');
Bruce Momjian's avatar
Bruce Momjian committed
/*
 * Write errors to stderr (or by equal means when stderr is
 * not available). Used before ereport/elog can be used
Bruce Momjian's avatar
Bruce Momjian committed
 * safely (memory context, GUC load etc)
Bruce Momjian's avatar
Bruce Momjian committed
	va_list		ap;

	va_start(ap, fmt);
#ifndef WIN32
	/* On Unix, we just fprintf to stderr */
	vfprintf(stderr, fmt, ap);
#else
Bruce Momjian's avatar
Bruce Momjian committed

	/*
	 * On Win32, we print to stderr if running on a console, or write to
	 * eventlog if running as a service
	 */
	if (pgwin32_is_service())	/* Running as a service */
Bruce Momjian's avatar
Bruce Momjian committed
		char		errbuf[2048];		/* Arbitrary size? */

		vsnprintf(errbuf, sizeof(errbuf), fmt, ap);
		write_eventlog(EVENTLOG_ERROR_TYPE, errbuf);
	}
Bruce Momjian's avatar
Bruce Momjian committed
	else
		/* Not running as service, write to stderr */
		vfprintf(stderr, fmt, ap);
#endif
	va_end(ap);
}