6#ifndef ALT_INTEGRATION_LOGGER_LOGGER_HPP
7#define ALT_INTEGRATION_LOGGER_LOGGER_HPP
31enum class LogLevel { debug, info, warn, error, critical, off };
51 virtual void log(
LogLevel,
const std::string&) {}
65 SetLogger(std::unique_ptr<L>(
new L()), log_lvl);
74#ifndef VERIBLOCK_POP_LOGGER_DISABLED
78#define VBK_LOG_FORMAT(format, ...) \
79 fmt::sprintf(std::string("%s: ") + format, __func__, ##__VA_ARGS__)
82#ifdef VBK_FUZZING_UNSAFE_FOR_PRODUCTION
88#define VBK_LOG(lvl, format, ...) \
91 auto& logger = altintegration::GetLogger(); \
92 if (logger.level <= lvl) { \
93 logger.log(lvl, VBK_LOG_FORMAT(format, ##__VA_ARGS__)); \
100#define VBK_LOG_DEBUG(format, ...) VBK_LOG(altintegration::LogLevel::debug, format, ##__VA_ARGS__)
102#define VBK_LOG_INFO(format, ...) VBK_LOG(altintegration::LogLevel::info, format, ##__VA_ARGS__)
104#define VBK_LOG_WARN(format, ...) VBK_LOG(altintegration::LogLevel::warn, format, ##__VA_ARGS__)
106#define VBK_LOG_ERROR(format, ...) VBK_LOG(altintegration::LogLevel::error, format, ##__VA_ARGS__)
108#define VBK_LOG_CRITICAL(format, ...) VBK_LOG(altintegration::LogLevel::critical, format, ##__VA_ARGS__)
114#define VBK_LOG_DEBUG(...)
116#define VBK_LOG_INFO(...)
118#define VBK_LOG_WARN(...)
120#define VBK_LOG_ERROR(...)
122#define VBK_LOG_CRITICAL(...)
127template <
typename S,
typename... Args>
128inline std::string format(
const S& format_str, Args&&... args) {
130 return fmt::format(format_str, (Args &&) args...);
131 }
catch (
const fmt::format_error&) {
132 VBK_LOG_WARN(
"invalid string formatting, str: %s", format_str);
std::string LevelToString(LogLevel l)
convert loglevel to string
LogLevel StringToLevel(const std::string &)
convert string to loglevel
void SetLogger(std::unique_ptr< Logger > lgr, LogLevel log_lvl=LogLevel::info)
setter for global logger instance
Logger & GetLogger()
getter for global logger instance