test: log error into stdout too.

This commit is contained in:
Leo Yuriev 2017-04-27 16:22:57 +03:00
parent 4b2cb66453
commit 150f2c0afc

View File

@ -106,24 +106,23 @@ bool output(loglevel priority, const char *format, va_list ap) {
if (rc != MDB_SUCCESS) if (rc != MDB_SUCCESS)
failure_perror("localtime_r()", rc); failure_perror("localtime_r()", rc);
last = (priority >= error) ? stderr : stdout; last = stdout;
fprintf(last, fprintf(last,
"[ %02d%02d%02d-%02d:%02d:%02d.%06d_%05u %-10s %.4s ] %s" /* TODO */, "[ %02d%02d%02d-%02d:%02d:%02d.%06d_%05u %-10s %.4s ] %s" /* TODO */,
tm.tm_year - 100, tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_year - 100, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min,
tm.tm_sec, chrono::fractional2us(now.fractional), osal_getpid(), tm.tm_sec, chrono::fractional2us(now.fractional), osal_getpid(),
prefix.c_str(), level2str(priority), suffix.c_str()); prefix.c_str(), level2str(priority), suffix.c_str());
vfprintf(last, format, ap); vfprintf(last, format, ap);
size_t len = strlen(format); size_t len = strlen(format);
char end = len ? format[len - 1] : '\0'; char end = len ? format[len - 1] : '\0';
switch (end) { switch (end) {
default: default:
putc('\n', last); putc('\n', last);
case '\n': case '\n':
fflush(last); fflush(last);
last = nullptr; last = nullptr;
if (priority > info)
fflushall();
case ' ': case ' ':
case '_': case '_':
case ':': case ':':
@ -135,6 +134,16 @@ bool output(loglevel priority, const char *format, va_list ap) {
case '\0': case '\0':
break; break;
} }
if (priority >= error && last != stderr) {
fprintf(stderr, "[ %05u %-10s %.4s ] %s", osal_getpid(), prefix.c_str(),
level2str(priority), suffix.c_str());
vfprintf(stderr, format, ap);
if (end != '\n')
putc('\n', stderr);
fflush(stderr);
}
return true; return true;
} }