mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-06 19:04:12 +08:00
test: fix logging va_copy() bug.
This commit is contained in:
parent
6d7bfeb87a
commit
bfa3e864b6
23
test/log.cc
23
test/log.cc
@ -18,8 +18,8 @@ static void fflushall() { fflush(nullptr); }
|
|||||||
|
|
||||||
void failure(const char *fmt, ...) {
|
void failure(const char *fmt, ...) {
|
||||||
va_list ap;
|
va_list ap;
|
||||||
fflush(NULL);
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
fflushall();
|
||||||
logging::output(logging::failure, fmt, ap);
|
logging::output(logging::failure, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
fflushall();
|
fflushall();
|
||||||
@ -74,7 +74,7 @@ const char *level2str(const loglevel level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool output(loglevel priority, const char *format, ...) {
|
bool output(const loglevel priority, const char *format, ...) {
|
||||||
if (priority < level)
|
if (priority < level)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ bool output(loglevel priority, const char *format, ...) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool output(loglevel priority, const char *format, va_list ap) {
|
bool output(const logging::loglevel priority, const char *format, va_list ap) {
|
||||||
if (last) {
|
if (last) {
|
||||||
putc('\n', last);
|
putc('\n', last);
|
||||||
fflush(last);
|
fflush(last);
|
||||||
@ -112,6 +112,10 @@ bool output(loglevel priority, const char *format, va_list ap) {
|
|||||||
tm.tm_year - 100, tm.tm_mon + 1, 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());
|
||||||
|
|
||||||
|
va_list ones;
|
||||||
|
if (priority >= error)
|
||||||
|
va_copy(ones, ap);
|
||||||
vfprintf(last, format, ap);
|
vfprintf(last, format, ap);
|
||||||
|
|
||||||
size_t len = strlen(format);
|
size_t len = strlen(format);
|
||||||
@ -135,14 +139,17 @@ bool output(loglevel priority, const char *format, va_list ap) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priority >= error && last != stderr) {
|
if (priority >= error) {
|
||||||
|
if (last != stderr) {
|
||||||
fprintf(stderr, "[ %05u %-10s %.4s ] %s", osal_getpid(), prefix.c_str(),
|
fprintf(stderr, "[ %05u %-10s %.4s ] %s", osal_getpid(), prefix.c_str(),
|
||||||
level2str(priority), suffix.c_str());
|
level2str(priority), suffix.c_str());
|
||||||
vfprintf(stderr, format, ap);
|
vfprintf(stderr, format, ones);
|
||||||
if (end != '\n')
|
if (end != '\n')
|
||||||
putc('\n', stderr);
|
putc('\n', stderr);
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
va_end(ones);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -258,6 +265,10 @@ void log_error(const char *msg, ...) {
|
|||||||
logging::last = nullptr;
|
logging::last = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void log_touble(const char *where, const char *what, int errnum) {
|
void log_trouble(const char *where, const char *what, int errnum) {
|
||||||
log_error("%s: %s %s", where, what, test_strerror(errnum));
|
log_error("%s: %s %s", where, what, test_strerror(errnum));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool log_enabled(const logging::loglevel priority) {
|
||||||
|
return (priority >= logging::level);
|
||||||
|
}
|
||||||
|
@ -47,8 +47,9 @@ const char *level2str(const loglevel level);
|
|||||||
void setup(loglevel level, const std::string &prefix);
|
void setup(loglevel level, const std::string &prefix);
|
||||||
void setup(const std::string &prefix);
|
void setup(const std::string &prefix);
|
||||||
|
|
||||||
bool output(loglevel priority, const char *format, va_list ap);
|
bool output(const loglevel priority, const char *format, va_list ap);
|
||||||
bool __printf_args(2, 3) output(loglevel priority, const char *format, ...);
|
bool __printf_args(2, 3)
|
||||||
|
output(const loglevel priority, const char *format, ...);
|
||||||
bool feed(const char *format, va_list ap);
|
bool feed(const char *format, va_list ap);
|
||||||
bool __printf_args(1, 2) feed(const char *format, ...);
|
bool __printf_args(1, 2) feed(const char *format, ...);
|
||||||
|
|
||||||
@ -78,7 +79,8 @@ void __printf_args(1, 2) log_notice(const char *msg, ...);
|
|||||||
void __printf_args(1, 2) log_warning(const char *msg, ...);
|
void __printf_args(1, 2) log_warning(const char *msg, ...);
|
||||||
void __printf_args(1, 2) log_error(const char *msg, ...);
|
void __printf_args(1, 2) log_error(const char *msg, ...);
|
||||||
|
|
||||||
void log_touble(const char *where, const char *what, int errnum);
|
void log_trouble(const char *where, const char *what, int errnum);
|
||||||
|
bool log_enabled(const logging::loglevel priority);
|
||||||
|
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
#define TRACE(...) log_trace(__VA_ARGS__)
|
#define TRACE(...) log_trace(__VA_ARGS__)
|
||||||
|
@ -61,7 +61,7 @@ struct txn_deleter : public std::unary_function<void, MDB_txn *> {
|
|||||||
void operator()(MDB_txn *txn) const {
|
void operator()(MDB_txn *txn) const {
|
||||||
int rc = mdbx_txn_abort(txn);
|
int rc = mdbx_txn_abort(txn);
|
||||||
if (rc)
|
if (rc)
|
||||||
log_touble(__func__, "mdbx_txn_abort()", rc);
|
log_trouble(__func__, "mdbx_txn_abort()", rc);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user