2020-11-08 05:47:47 +00:00
|
|
|
/*
|
|
|
|
* Modern effects for a modern Streamer
|
|
|
|
* Copyright (C) 2020 Michael Fabian Dirks
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "util-logging.hpp"
|
|
|
|
#include "common.hpp"
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
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);
|
|
|
|
buffer.resize(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());
|
|
|
|
}
|