mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-02 02:14:13 +08:00
mdbx-test: доработка логирования для использования после/из глобальных деструкторов.
This commit is contained in:
parent
cfce4ef4d3
commit
100e95957c
@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
#define IP_PRINTF_ARG_HOST(addr) \
|
#define IP_PRINTF_ARG_HOST(addr) \
|
||||||
(int)((addr) >> 24), (int)((addr) >> 16 & 0xff), (int)((addr) >> 8 & 0xff), \
|
(int)((addr) >> 24), (int)((addr) >> 16 & 0xff), (int)((addr) >> 8 & 0xff), \
|
||||||
(int)((addr)&0xff)
|
(int)((addr) & 0xff)
|
||||||
|
|
||||||
char opt_db_path[PATH_MAX] = "./mdbx_bench2";
|
char opt_db_path[PATH_MAX] = "./mdbx_bench2";
|
||||||
static MDBX_env *env;
|
static MDBX_env *env;
|
||||||
|
48
test/log.c++
48
test/log.c++
@ -53,8 +53,16 @@ static void mdbx_logger(MDBX_log_level_t priority, const char *function,
|
|||||||
|
|
||||||
namespace logging {
|
namespace logging {
|
||||||
|
|
||||||
static std::string prefix;
|
/* логирование может быть вызвано после деструкторов */
|
||||||
static std::string suffix;
|
static char prefix_buf[64];
|
||||||
|
static size_t prefix_len;
|
||||||
|
static std::string suffix_buf;
|
||||||
|
static const char *suffix_ptr = "~~~";
|
||||||
|
struct suffix_cleaner {
|
||||||
|
suffix_cleaner() { suffix_ptr = ""; }
|
||||||
|
~suffix_cleaner() { suffix_ptr = "~~~"; }
|
||||||
|
} static anchor;
|
||||||
|
|
||||||
static loglevel level;
|
static loglevel level;
|
||||||
static FILE *flow;
|
static FILE *flow;
|
||||||
|
|
||||||
@ -67,11 +75,14 @@ void setlevel(loglevel priority) {
|
|||||||
log_trace("set mdbx debug-opts: 0x%02x", rc);
|
log_trace("set mdbx debug-opts: 0x%02x", rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup(const std::string &_prefix) { prefix = _prefix; }
|
void setup(const std::string &prefix) {
|
||||||
|
prefix_len = std::min(prefix.size(), sizeof(prefix_buf) - 1);
|
||||||
|
memcpy(prefix_buf, prefix.data(), prefix_len);
|
||||||
|
}
|
||||||
|
|
||||||
void setup(loglevel priority, const std::string &_prefix) {
|
void setup(loglevel priority, const std::string &prefix) {
|
||||||
setlevel(priority);
|
setlevel(priority);
|
||||||
setup(_prefix);
|
setup(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *level2str(const loglevel alevel) {
|
const char *level2str(const loglevel alevel) {
|
||||||
@ -138,7 +149,7 @@ void output_nocheckloglevel_ap(const logging::loglevel priority,
|
|||||||
"[ %02d%02d%02d-%02d:%02d:%02d.%06d_%05lu %-10s %.4s ] %s" /* TODO */,
|
"[ %02d%02d%02d-%02d:%02d:%02d.%06d_%05lu %-10s %.4s ] %s" /* TODO */,
|
||||||
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), (long)osal_getpid(),
|
tm.tm_sec, chrono::fractional2us(now.fractional), (long)osal_getpid(),
|
||||||
prefix.c_str(), level2str(priority), suffix.c_str());
|
prefix_buf, level2str(priority), suffix_ptr);
|
||||||
|
|
||||||
va_list ones;
|
va_list ones;
|
||||||
memset(&ones, 0, sizeof(ones)) /* zap MSVC and other goofy compilers */;
|
memset(&ones, 0, sizeof(ones)) /* zap MSVC and other goofy compilers */;
|
||||||
@ -171,8 +182,8 @@ void output_nocheckloglevel_ap(const logging::loglevel priority,
|
|||||||
if (same_or_higher(priority, error)) {
|
if (same_or_higher(priority, error)) {
|
||||||
if (flow)
|
if (flow)
|
||||||
flow = stderr;
|
flow = stderr;
|
||||||
fprintf(stderr, "[ %05lu %-10s %.4s ] %s", (long)osal_getpid(),
|
fprintf(stderr, "[ %05lu %-10s %.4s ] %s", (long)osal_getpid(), prefix_buf,
|
||||||
prefix.c_str(), level2str(priority), suffix.c_str());
|
level2str(priority), suffix_ptr);
|
||||||
vfprintf(stderr, format, ones);
|
vfprintf(stderr, format, ones);
|
||||||
va_end(ones);
|
va_end(ones);
|
||||||
}
|
}
|
||||||
@ -207,29 +218,36 @@ bool feed(const char *format, ...) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
local_suffix::local_suffix(const char *c_str)
|
local_suffix::local_suffix(const char *c_str)
|
||||||
: trim_pos(suffix.size()), indent(0) {
|
: trim_pos(suffix_buf.size()), indent(0) {
|
||||||
suffix.append(c_str);
|
suffix_buf.append(c_str);
|
||||||
|
suffix_ptr = suffix_buf.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
local_suffix::local_suffix(const std::string &str)
|
local_suffix::local_suffix(const std::string &str)
|
||||||
: trim_pos(suffix.size()), indent(0) {
|
: trim_pos(suffix_buf.size()), indent(0) {
|
||||||
suffix.append(str);
|
suffix_buf.append(str);
|
||||||
|
suffix_ptr = suffix_buf.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void local_suffix::push() {
|
void local_suffix::push() {
|
||||||
indent += 1;
|
indent += 1;
|
||||||
suffix.push_back('\t');
|
suffix_buf.push_back('\t');
|
||||||
|
suffix_ptr = suffix_buf.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void local_suffix::pop() {
|
void local_suffix::pop() {
|
||||||
assert(indent > 0);
|
assert(indent > 0);
|
||||||
if (indent > 0) {
|
if (indent > 0) {
|
||||||
indent -= 1;
|
indent -= 1;
|
||||||
suffix.pop_back();
|
suffix_buf.pop_back();
|
||||||
|
suffix_ptr = suffix_buf.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local_suffix::~local_suffix() { suffix.erase(trim_pos); }
|
local_suffix::~local_suffix() {
|
||||||
|
suffix_buf.erase(trim_pos);
|
||||||
|
suffix_ptr = suffix_buf.c_str();
|
||||||
|
}
|
||||||
|
|
||||||
void progress_canary(bool active) {
|
void progress_canary(bool active) {
|
||||||
static chrono::time progress_timestamp;
|
static chrono::time progress_timestamp;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user