summaryrefslogtreecommitdiff
path: root/libs/libmdbx/src/test/log.cc
diff options
context:
space:
mode:
authorGeorge Hazan <ghazan@miranda.im>2018-09-14 16:33:56 +0300
committerGeorge Hazan <ghazan@miranda.im>2018-09-14 16:33:56 +0300
commit50d176bfe78d4b5ffd829a874e503facef398e7d (patch)
tree3048927747b53a7c79ef73a5671d9ec912322382 /libs/libmdbx/src/test/log.cc
parentcc03b109287f4c818a4d6df09cbfa48784e1e4a6 (diff)
merge with libmdbx release
Diffstat (limited to 'libs/libmdbx/src/test/log.cc')
-rw-r--r--libs/libmdbx/src/test/log.cc38
1 files changed, 37 insertions, 1 deletions
diff --git a/libs/libmdbx/src/test/log.cc b/libs/libmdbx/src/test/log.cc
index 521e1d6900..7bc3ecf613 100644
--- a/libs/libmdbx/src/test/log.cc
+++ b/libs/libmdbx/src/test/log.cc
@@ -37,6 +37,31 @@ void __noreturn failure_perror(const char *what, int errnum) {
//-----------------------------------------------------------------------------
+static void mdbx_logger(int type, const char *function, int line,
+ const char *msg, va_list args) {
+ logging::loglevel level = logging::info;
+ if (type & MDBX_DBG_EXTRA)
+ level = logging::extra;
+ if (type & MDBX_DBG_TRACE)
+ level = logging::trace;
+ if (type & MDBX_DBG_PRINT)
+ level = logging::verbose;
+
+ if (!function)
+ function = "unknown";
+ if (type & MDBX_DBG_ASSERT) {
+ log_error("mdbx: assertion failure: %s, %d", function, line);
+ level = logging::failure;
+ }
+
+ if (logging::output(
+ level,
+ strncmp(function, "mdbx_", 5) == 0 ? "%s: " : "mdbx: %s: ", function))
+ logging::feed(msg, args);
+ if (type & MDBX_DBG_ASSERT)
+ abort();
+}
+
namespace logging {
static std::string prefix;
@@ -44,8 +69,19 @@ static std::string suffix;
static loglevel level;
static FILE *last;
-void setup(loglevel _level, const std::string &_prefix) {
+void setlevel(loglevel _level) {
level = (_level > error) ? failure : _level;
+ int mdbx_dbg_opts = MDBX_DBG_ASSERT | MDBX_DBG_JITTER | MDBX_DBG_DUMP;
+ if (level <= trace)
+ mdbx_dbg_opts |= MDBX_DBG_TRACE;
+ if (level <= verbose)
+ mdbx_dbg_opts |= MDBX_DBG_PRINT;
+ int rc = mdbx_setup_debug(mdbx_dbg_opts, mdbx_logger);
+ log_trace("set mdbx debug-opts: 0x%02x", rc);
+}
+
+void setup(loglevel _level, const std::string &_prefix) {
+ setlevel(_level);
prefix = _prefix;
}