Open bwrsandman opened 11 months ago
Example use of custom logger using spdlog in c++
void unshield_log_handler([[maybe_unused]] void* userdata, int level, const char* file, int line, const char* format, va_list args)
{
spdlog::level::level_enum spdlogLevel;
switch (level)
{
case UNSHIELD_LOG_LEVEL_TRACE:
spdlogLevel = spdlog::level::trace;
break;
case UNSHIELD_LOG_LEVEL_WARNING:
spdlogLevel = spdlog::level::warn;
break;
case UNSHIELD_LOG_LEVEL_ERROR:
spdlogLevel = spdlog::level::err;
break;
}
// Get the length of the message
va_list args_copy;
va_copy(args_copy, args);
int length = vsnprintf(nullptr, 0, format, args_copy) + 1;
va_end(args_copy);
std::vector<char> message(length);
vsnprintf(message.data(), message.size(), format, args);
SPDLOG_LOGGER_CALL(spdlog::get("filesystem"), spdlogLevel, "unshield: {}", message.data());
}
@bwrsandman sorry about the merge conflict!
rebased!
Add levels to public API. Default to old stderr logging method. Add function pointer and userdata pointer as static globals.
Implements #179