mdbx-tools: добавление логирования ошибок/предупреждений по все утилиты.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2025-01-12 14:38:20 +03:00
parent e5fe279632
commit c751977bf7
5 changed files with 84 additions and 3 deletions

View File

@ -53,6 +53,21 @@ static void usage(const char *prog) {
exit(EXIT_FAILURE);
}
static void logger(MDBX_log_level_t level, const char *function, int line, const char *fmt, va_list args) {
static const char *const prefixes[] = {
"!!!fatal: ", // 0 fatal
" ! ", // 1 error
" ~ ", // 2 warning
" ", // 3 notice
" //", // 4 verbose
};
if (level < MDBX_LOG_DEBUG) {
if (function && line)
fprintf(stderr, "%s", prefixes[level]);
vfprintf(stderr, fmt, args);
}
}
int main(int argc, char *argv[]) {
int rc;
MDBX_env *env = nullptr;
@ -117,6 +132,7 @@ int main(int argc, char *argv[]) {
mdbx_version.git.describe, mdbx_version.git.datetime, mdbx_version.git.tree, argv[1],
(argc == 2) ? "stdout" : argv[2]);
fflush(nullptr);
mdbx_setup_debug(MDBX_LOG_NOTICE, MDBX_DBG_DONTCHANGE, logger);
}
act = "opening environment";

View File

@ -57,6 +57,21 @@ static void error(const char *func, int rc) {
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc, mdbx_strerror(rc));
}
static void logger(MDBX_log_level_t level, const char *function, int line, const char *fmt, va_list args) {
static const char *const prefixes[] = {
"!!!fatal: ", // 0 fatal
" ! ", // 1 error
" ~ ", // 2 warning
" ", // 3 notice
" //", // 4 verbose
};
if (level < MDBX_LOG_DEBUG) {
if (function && line)
fprintf(stderr, "%s", prefixes[level]);
vfprintf(stderr, fmt, args);
}
}
int main(int argc, char *argv[]) {
int i, rc;
MDBX_env *env;
@ -126,6 +141,7 @@ int main(int argc, char *argv[]) {
printf("mdbx_drop %s (%s, T-%s)\nRunning for %s/%s...\n", mdbx_version.git.describe, mdbx_version.git.datetime,
mdbx_version.git.tree, envname, subname ? subname : "@MAIN");
fflush(nullptr);
mdbx_setup_debug(MDBX_LOG_NOTICE, MDBX_DBG_DONTCHANGE, logger);
}
rc = mdbx_env_create(&env);

View File

@ -223,6 +223,21 @@ static void usage(void) {
exit(EXIT_FAILURE);
}
static void logger(MDBX_log_level_t level, const char *function, int line, const char *fmt, va_list args) {
static const char *const prefixes[] = {
"!!!fatal: ", // 0 fatal
" ! ", // 1 error
" ~ ", // 2 warning
" ", // 3 notice
" //", // 4 verbose
};
if (level < MDBX_LOG_DEBUG) {
if (function && line)
fprintf(stderr, "%s", prefixes[level]);
vfprintf(stderr, fmt, args);
}
}
static int equal_or_greater(const MDBX_val *a, const MDBX_val *b) {
return (a->iov_len == b->iov_len && memcmp(a->iov_base, b->iov_base, a->iov_len) == 0) ? 0 : 1;
}
@ -330,6 +345,7 @@ int main(int argc, char *argv[]) {
fprintf(stderr, "mdbx_dump %s (%s, T-%s)\nRunning for %s...\n", mdbx_version.git.describe,
mdbx_version.git.datetime, mdbx_version.git.tree, envname);
fflush(nullptr);
mdbx_setup_debug(MDBX_LOG_NOTICE, MDBX_DBG_DONTCHANGE, logger);
}
err = mdbx_env_create(&env);

View File

@ -51,6 +51,21 @@ static void error(const char *func, int rc) {
}
}
static void logger(MDBX_log_level_t level, const char *function, int line, const char *fmt, va_list args) {
static const char *const prefixes[] = {
"!!!fatal: ", // 0 fatal
" ! ", // 1 error
" ~ ", // 2 warning
" ", // 3 notice
" //", // 4 verbose
};
if (level < MDBX_LOG_DEBUG) {
if (function && line)
fprintf(stderr, "%s", prefixes[level]);
vfprintf(stderr, fmt, args);
}
}
static char *valstr(char *line, const char *item) {
const size_t len = strlen(item);
if (strncmp(line, item, len) != 0)
@ -544,10 +559,12 @@ int main(int argc, char *argv[]) {
#endif /* !WINDOWS */
envname = argv[optind];
if (!quiet)
if (!quiet) {
printf("mdbx_load %s (%s, T-%s)\nRunning for %s...\n", mdbx_version.git.describe, mdbx_version.git.datetime,
mdbx_version.git.tree, envname);
fflush(nullptr);
mdbx_setup_debug(MDBX_LOG_NOTICE, MDBX_DBG_DONTCHANGE, logger);
}
dbuf.iov_len = 4096;
dbuf.iov_base = osal_malloc(dbuf.iov_len);

View File

@ -92,6 +92,21 @@ static void error(const char *func, int rc) {
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc, mdbx_strerror(rc));
}
static void logger(MDBX_log_level_t level, const char *function, int line, const char *fmt, va_list args) {
static const char *const prefixes[] = {
"!!!fatal: ", // 0 fatal
" ! ", // 1 error
" ~ ", // 2 warning
" ", // 3 notice
" //", // 4 verbose
};
if (level < MDBX_LOG_DEBUG) {
if (function && line)
fprintf(stderr, "%s", prefixes[level]);
vfprintf(stderr, fmt, args);
}
}
int main(int argc, char *argv[]) {
int opt, rc;
MDBX_env *env;
@ -183,6 +198,7 @@ int main(int argc, char *argv[]) {
printf("mdbx_stat %s (%s, T-%s)\nRunning for %s...\n", mdbx_version.git.describe, mdbx_version.git.datetime,
mdbx_version.git.tree, envname);
fflush(nullptr);
mdbx_setup_debug(MDBX_LOG_NOTICE, MDBX_DBG_DONTCHANGE, logger);
}
rc = mdbx_env_create(&env);
@ -287,7 +303,7 @@ int main(int argc, char *argv[]) {
goto txn_abort;
}
if (rc == MDBX_RESULT_TRUE)
printf("Reader Table is empty\n");
printf("Reader Table is absent\n");
else if (rc == MDBX_SUCCESS && rdrinfo > 1) {
int dead;
rc = mdbx_reader_check(env, &dead);