mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-29 23:19:20 +08:00
test: fix logging va_copy() bug.
This commit is contained in:
parent
6d7bfeb87a
commit
bfa3e864b6
33
test/log.cc
33
test/log.cc
@ -18,8 +18,8 @@ static void fflushall() { fflush(nullptr); }
|
||||
|
||||
void failure(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
fflush(NULL);
|
||||
va_start(ap, fmt);
|
||||
fflushall();
|
||||
logging::output(logging::failure, fmt, ap);
|
||||
va_end(ap);
|
||||
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)
|
||||
return false;
|
||||
|
||||
@ -85,7 +85,7 @@ bool output(loglevel priority, const char *format, ...) {
|
||||
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) {
|
||||
putc('\n', 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_sec, chrono::fractional2us(now.fractional), osal_getpid(),
|
||||
prefix.c_str(), level2str(priority), suffix.c_str());
|
||||
|
||||
va_list ones;
|
||||
if (priority >= error)
|
||||
va_copy(ones, ap);
|
||||
vfprintf(last, format, ap);
|
||||
|
||||
size_t len = strlen(format);
|
||||
@ -135,13 +139,16 @@ bool output(loglevel priority, const char *format, va_list ap) {
|
||||
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);
|
||||
if (priority >= error) {
|
||||
if (last != stderr) {
|
||||
fprintf(stderr, "[ %05u %-10s %.4s ] %s", osal_getpid(), prefix.c_str(),
|
||||
level2str(priority), suffix.c_str());
|
||||
vfprintf(stderr, format, ones);
|
||||
if (end != '\n')
|
||||
putc('\n', stderr);
|
||||
fflush(stderr);
|
||||
}
|
||||
va_end(ones);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -258,6 +265,10 @@ void log_error(const char *msg, ...) {
|
||||
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));
|
||||
}
|
||||
|
||||
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(const std::string &prefix);
|
||||
|
||||
bool output(loglevel priority, const char *format, va_list ap);
|
||||
bool __printf_args(2, 3) output(loglevel priority, const char *format, ...);
|
||||
bool output(const loglevel priority, const char *format, va_list ap);
|
||||
bool __printf_args(2, 3)
|
||||
output(const loglevel priority, const char *format, ...);
|
||||
bool feed(const char *format, va_list ap);
|
||||
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_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
|
||||
#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 {
|
||||
int rc = mdbx_txn_abort(txn);
|
||||
if (rc)
|
||||
log_touble(__func__, "mdbx_txn_abort()", rc);
|
||||
log_trouble(__func__, "mdbx_txn_abort()", rc);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user