From e875d2128eaac4abe007cc333939e2f3d60edc7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Thu, 21 Apr 2022 19:42:57 +0300 Subject: [PATCH] mdbx-test: add `--loglevel=` option. --- test/config.cc | 65 +++++++++++++++++++++++++++++++++++++++++++++++++- test/config.h | 2 ++ test/main.cc | 8 +++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/test/config.cc b/test/config.cc index 9db481fd..61b299b4 100644 --- a/test/config.cc +++ b/test/config.cc @@ -106,7 +106,7 @@ bool parse_option(int argc, char *const argv[], int &narg, while (true) { if (!scan->verb) - failure("Unknown verb '%.*s', for option '==%s'\n", (int)len, list, + failure("Unknown verb '%.*s', for option '--%s'\n", (int)len, list, option); if (strlen(scan->verb) == len && strncmp(list, scan->verb, len) == 0) { mask = strikethrough ? mask & ~scan->mask : mask | scan->mask; @@ -257,6 +257,69 @@ bool parse_option(int argc, char *const argv[], int &narg, const char *option, return false; } +bool parse_option(int argc, char *const argv[], int &narg, const char *option, + logging::loglevel &loglevel) { + const char *value_cstr; + if (!parse_option(argc, argv, narg, option, &value_cstr)) + return false; + + if (strcmp(value_cstr, "min") == 0 || strcmp(value_cstr, "minimal") == 0 || + strcmp(value_cstr, "fatal") == 0) { + loglevel = logging::failure; + return true; + } + + if (strcmp(value_cstr, "error") == 0 || strcmp(value_cstr, "err") == 0) { + loglevel = logging::error; + return true; + } + + if (strcmp(value_cstr, "warning") == 0 || strcmp(value_cstr, "warn") == 0) { + loglevel = logging::error; + return true; + } + + if (strcmp(value_cstr, "default") == 0 || strcmp(value_cstr, "notice") == 0) { + loglevel = logging::notice; + return true; + } + + if (strcmp(value_cstr, "verbose") == 0) { + loglevel = logging::verbose; + return true; + } + + if (strcmp(value_cstr, "debug") == 0) { + loglevel = logging::debug; + return true; + } + + if (strcmp(value_cstr, "trace") == 0) { + loglevel = logging::trace; + return true; + } + + if (strcmp(value_cstr, "max") == 0 || strcmp(value_cstr, "maximal") == 0 || + strcmp(value_cstr, "extra") == 0) { + loglevel = logging::extra; + return true; + } + + char *suffix = nullptr; + unsigned long long raw = strtoull(value_cstr, &suffix, 0); + if ((suffix && *suffix) || errno) { + suffix = nullptr; + errno = 0; + raw = strtoull(value_cstr, &suffix, 10); + } + if ((!suffix || !*suffix) && !errno && raw < 8) { + loglevel = static_cast(raw); + return true; + } + + failure("Unknown log-level '%s', for option '--%s'\n", value_cstr, option); +} + bool parse_option(int argc, char *const argv[], int &narg, const char *option, bool &value) { const char *value_cstr = nullptr; diff --git a/test/config.h b/test/config.h index 27286426..8c93981e 100644 --- a/test/config.h +++ b/test/config.h @@ -133,6 +133,8 @@ inline bool parse_option_intptr(int argc, char *const argv[], int &narg, int32_t(maxval), int32_t(default_value)); } +bool parse_option(int argc, char *const argv[], int &narg, const char *option, + logging::loglevel &); //----------------------------------------------------------------------------- struct keygen_params_pod { diff --git a/test/main.cc b/test/main.cc index c201c20e..b4b8022b 100644 --- a/test/main.cc +++ b/test/main.cc @@ -24,6 +24,7 @@ MDBX_NORETURN void usage(void) { "usage:\n" " --help or -h Show this text\n" "Common parameters:\n" + " --loglevel=[0-7]|[extra..fatal]" " --pathname=... Path and/or name of database files\n" " --repeat=N Set repeat counter\n" " --threads=N Number of thread (unsupported for now)\n" @@ -319,6 +320,13 @@ int main(int argc, char *const argv[]) { config::duration, 1)) continue; + logging::loglevel loglevel; + if (config::parse_option(argc, argv, narg, "loglevel", loglevel)) { + logging::setup(loglevel, "main"); + params.loglevel = static_cast(loglevel); + continue; + } + const char *value = nullptr; if (config::parse_option(argc, argv, narg, "case", &value)) { fixup4qemu(params);