mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 06:08:21 +08:00
test: add us-timestamp to logs.
This commit is contained in:
parent
e7e8e1c59a
commit
925064aa11
26
test/log.cc
26
test/log.cc
@ -88,15 +88,30 @@ bool output(loglevel priority, const char *format, ...) {
|
|||||||
bool output(loglevel priority, const char *format, va_list ap) {
|
bool output(loglevel priority, const char *format, va_list ap) {
|
||||||
if (last) {
|
if (last) {
|
||||||
putc('\n', last);
|
putc('\n', last);
|
||||||
|
fflush(last);
|
||||||
last = nullptr;
|
last = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priority < level)
|
if (priority < level)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
chrono::time now = chrono::now_realtime();
|
||||||
|
struct tm tm;
|
||||||
|
time_t time = now.utc;
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
int rc = _localtime32_s(&tm, (const __time32_t *)&now.utc);
|
||||||
|
#else
|
||||||
|
int rc = localtime_r(&time, &tm) ? MDB_SUCCESS : errno;
|
||||||
|
#endif
|
||||||
|
if (rc != MDB_SUCCESS)
|
||||||
|
failure_perror("localtime_r()", rc);
|
||||||
|
|
||||||
last = (priority >= error) ? stderr : stdout;
|
last = (priority >= error) ? stderr : stdout;
|
||||||
fprintf(last, "[ %u%10s %.4s ] %s" /* TODO */, osal_getpid(), prefix.c_str(),
|
fprintf(last,
|
||||||
level2str(priority), suffix.c_str());
|
"[ %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_sec, chrono::fractional2us(now.fractional), osal_getpid(),
|
||||||
|
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);
|
||||||
@ -105,9 +120,10 @@ bool output(loglevel priority, const char *format, va_list ap) {
|
|||||||
default:
|
default:
|
||||||
putc('\n', last);
|
putc('\n', last);
|
||||||
case '\n':
|
case '\n':
|
||||||
|
fflush(last);
|
||||||
|
last = nullptr;
|
||||||
if (priority > info)
|
if (priority > info)
|
||||||
fflushall();
|
fflushall();
|
||||||
last = nullptr;
|
|
||||||
case ' ':
|
case ' ':
|
||||||
case '_':
|
case '_':
|
||||||
case ':':
|
case ':':
|
||||||
@ -128,8 +144,10 @@ bool feed(const char *format, va_list ap) {
|
|||||||
|
|
||||||
vfprintf(last, format, ap);
|
vfprintf(last, format, ap);
|
||||||
size_t len = strlen(format);
|
size_t len = strlen(format);
|
||||||
if (len && format[len - 1] == '\n')
|
if (len && format[len - 1] == '\n') {
|
||||||
|
fflush(last);
|
||||||
last = nullptr;
|
last = nullptr;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user