mdbx-test: add --loglevel= option.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-04-21 19:42:57 +03:00
parent bb377fd20e
commit e875d2128e
3 changed files with 74 additions and 1 deletions

View File

@ -106,7 +106,7 @@ bool parse_option<unsigned>(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<logging::loglevel>(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;

View File

@ -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 {

View File

@ -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<uint8_t>(loglevel);
continue;
}
const char *value = nullptr;
if (config::parse_option(argc, argv, narg, "case", &value)) {
fixup4qemu(params);