2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// Copyright (C) 2021 William Pettersson <william@ewpettersson.se>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2020-11-08 05:47:47 +00:00
|
|
|
|
|
|
|
#include "util-logging.hpp"
|
|
|
|
#include "common.hpp"
|
2022-08-29 10:29:44 +00:00
|
|
|
|
|
|
|
#include "warning-disable.hpp"
|
2020-11-08 05:47:47 +00:00
|
|
|
#include <stdarg.h>
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-enable.hpp"
|
2020-11-08 05:47:47 +00:00
|
|
|
|
2021-06-08 02:18:02 +00:00
|
|
|
void streamfx::util::logging::log(level lvl, const char* format, ...)
|
2020-11-08 05:47:47 +00:00
|
|
|
{
|
|
|
|
const static std::map<level, int32_t> level_map = {
|
|
|
|
{level::LEVEL_DEBUG, LOG_DEBUG},
|
|
|
|
{level::LEVEL_INFO, LOG_INFO},
|
|
|
|
{level::LEVEL_WARN, LOG_WARNING},
|
|
|
|
{level::LEVEL_ERROR, LOG_ERROR},
|
|
|
|
};
|
|
|
|
thread_local static std::vector<char> buffer;
|
|
|
|
|
|
|
|
va_list vargs;
|
|
|
|
va_start(vargs, format);
|
|
|
|
|
2021-09-20 09:17:51 +00:00
|
|
|
va_list vargs_copy;
|
|
|
|
va_copy(vargs_copy, vargs);
|
2020-11-08 05:47:47 +00:00
|
|
|
int32_t ret = vsnprintf(buffer.data(), buffer.size(), format, vargs);
|
2022-08-28 11:44:00 +00:00
|
|
|
buffer.resize(static_cast<size_t>(ret) + 1);
|
2021-09-20 09:17:51 +00:00
|
|
|
ret = vsnprintf(buffer.data(), buffer.size(), format, vargs_copy);
|
2020-11-08 05:47:47 +00:00
|
|
|
|
|
|
|
va_end(vargs);
|
2021-09-20 09:17:51 +00:00
|
|
|
va_end(vargs_copy);
|
2020-11-08 05:47:47 +00:00
|
|
|
|
|
|
|
blog(level_map.at(lvl), "[StreamFX] %s", buffer.data());
|
|
|
|
}
|