2024-05-19 22:07:58 +03:00
|
|
|
/// \author Леонид Юрьев aka Leonid Yuriev <leo@yuriev.ru> \date 2015-2024
|
|
|
|
/// \copyright SPDX-License-Identifier: Apache-2.0
|
2017-03-30 18:54:57 +03:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-11-08 16:17:14 +03:00
|
|
|
#include "base.h++"
|
|
|
|
#include "chrono.h++"
|
2017-03-30 18:54:57 +03:00
|
|
|
|
2020-09-14 16:40:46 +03:00
|
|
|
MDBX_NORETURN void usage(void);
|
|
|
|
MDBX_NORETURN void MDBX_PRINTF_ARGS(1, 2) failure(const char *fmt, ...);
|
|
|
|
MDBX_NORETURN void failure_perror(const char *what, int errnum);
|
2017-03-30 18:54:57 +03:00
|
|
|
const char *test_strerror(int errnum);
|
|
|
|
|
2017-04-11 12:55:16 +03:00
|
|
|
namespace logging {
|
2017-03-30 18:54:57 +03:00
|
|
|
|
|
|
|
enum loglevel {
|
2019-09-24 02:07:00 +03:00
|
|
|
extra = MDBX_LOG_EXTRA,
|
|
|
|
trace = MDBX_LOG_TRACE,
|
|
|
|
debug = MDBX_LOG_DEBUG,
|
2019-10-01 22:01:45 +03:00
|
|
|
verbose = MDBX_LOG_VERBOSE,
|
2019-09-24 02:07:00 +03:00
|
|
|
notice = MDBX_LOG_NOTICE,
|
|
|
|
warning = MDBX_LOG_WARN,
|
|
|
|
error = MDBX_LOG_ERROR,
|
|
|
|
failure = MDBX_LOG_FATAL
|
2017-03-30 18:54:57 +03:00
|
|
|
};
|
|
|
|
|
2019-10-01 22:01:45 +03:00
|
|
|
inline bool lower(loglevel left, loglevel right) {
|
|
|
|
static_assert(MDBX_LOG_EXTRA > MDBX_LOG_FATAL, "WTF?");
|
|
|
|
return left > right;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool same_or_higher(loglevel left, loglevel right) {
|
|
|
|
return left <= right;
|
|
|
|
}
|
|
|
|
|
2017-03-30 18:54:57 +03:00
|
|
|
const char *level2str(const loglevel level);
|
2019-10-01 22:01:45 +03:00
|
|
|
void setup(loglevel priority, const std::string &prefix);
|
2017-03-30 18:54:57 +03:00
|
|
|
void setup(const std::string &prefix);
|
2019-10-01 22:01:45 +03:00
|
|
|
void setlevel(loglevel priority);
|
2017-03-30 18:54:57 +03:00
|
|
|
|
2019-10-20 08:14:33 +03:00
|
|
|
void output_nocheckloglevel_ap(const loglevel priority, const char *format,
|
|
|
|
va_list ap);
|
2020-09-14 16:40:46 +03:00
|
|
|
bool MDBX_PRINTF_ARGS(2, 3)
|
2017-05-17 15:46:44 +03:00
|
|
|
output(const loglevel priority, const char *format, ...);
|
2018-09-14 15:13:05 +03:00
|
|
|
bool feed_ap(const char *format, va_list ap);
|
2020-09-14 16:40:46 +03:00
|
|
|
bool MDBX_PRINTF_ARGS(1, 2) feed(const char *format, ...);
|
2023-11-10 21:14:32 +03:00
|
|
|
void ln();
|
2017-04-11 12:55:16 +03:00
|
|
|
|
2020-09-14 16:40:46 +03:00
|
|
|
void inline MDBX_PRINTF_ARGS(2, 3)
|
2019-10-20 08:14:33 +03:00
|
|
|
output_nocheckloglevel(const loglevel priority, const char *format, ...) {
|
|
|
|
va_list ap;
|
|
|
|
va_start(ap, format);
|
|
|
|
output_nocheckloglevel_ap(priority, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
2019-10-02 01:17:09 +03:00
|
|
|
void progress_canary(bool active);
|
|
|
|
|
2017-04-11 12:55:16 +03:00
|
|
|
class local_suffix {
|
|
|
|
protected:
|
|
|
|
size_t trim_pos;
|
|
|
|
int indent;
|
|
|
|
|
|
|
|
public:
|
|
|
|
local_suffix(const local_suffix &) = delete;
|
|
|
|
local_suffix(const local_suffix &&) = delete;
|
|
|
|
const local_suffix &operator=(const local_suffix &) = delete;
|
|
|
|
|
|
|
|
local_suffix(const char *c_str);
|
|
|
|
local_suffix(const std::string &str);
|
|
|
|
void push();
|
|
|
|
void pop();
|
|
|
|
~local_suffix();
|
|
|
|
};
|
2017-03-30 18:54:57 +03:00
|
|
|
|
2018-06-18 21:29:12 +03:00
|
|
|
} // namespace logging
|
2017-03-30 18:54:57 +03:00
|
|
|
|
2022-06-02 16:50:11 +03:00
|
|
|
void MDBX_PRINTF_ARGS(1, 2) static inline log_null(const char *msg, ...) {
|
|
|
|
return (void)msg;
|
|
|
|
}
|
2020-09-14 16:40:46 +03:00
|
|
|
void MDBX_PRINTF_ARGS(1, 2) log_extra(const char *msg, ...);
|
|
|
|
void MDBX_PRINTF_ARGS(1, 2) log_trace(const char *msg, ...);
|
|
|
|
void MDBX_PRINTF_ARGS(1, 2) log_debug(const char *msg, ...);
|
|
|
|
void MDBX_PRINTF_ARGS(1, 2) log_verbose(const char *msg, ...);
|
|
|
|
void MDBX_PRINTF_ARGS(1, 2) log_notice(const char *msg, ...);
|
|
|
|
void MDBX_PRINTF_ARGS(1, 2) log_warning(const char *msg, ...);
|
|
|
|
void MDBX_PRINTF_ARGS(1, 2) log_error(const char *msg, ...);
|
2017-03-30 18:54:57 +03:00
|
|
|
|
2017-05-17 15:46:44 +03:00
|
|
|
void log_trouble(const char *where, const char *what, int errnum);
|
2018-03-19 16:51:10 +03:00
|
|
|
void log_flush(void);
|
2017-05-17 15:46:44 +03:00
|
|
|
bool log_enabled(const logging::loglevel priority);
|
2017-03-30 18:54:57 +03:00
|
|
|
|
2024-05-19 22:07:58 +03:00
|
|
|
#undef TRACE
|
2017-03-30 18:54:57 +03:00
|
|
|
#ifdef _DEBUG
|
|
|
|
#define TRACE(...) log_trace(__VA_ARGS__)
|
|
|
|
#else
|
2022-06-02 16:50:11 +03:00
|
|
|
#define TRACE(...) log_null(__VA_ARGS__)
|
2017-03-30 18:54:57 +03:00
|
|
|
#endif
|