project: Unify logging structure

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-09-07 04:29:41 +02:00
parent b8f23fa8ab
commit 380d75f770
4 changed files with 67 additions and 33 deletions

View file

@ -19,16 +19,27 @@
// SOFTWARE. // SOFTWARE.
#include "gfx-lut.hpp" #include "gfx-lut.hpp"
#include <mutex> #include <mutex>
#include "obs/gs/gs-helper.hpp" #include "obs/gs/gs-helper.hpp"
#include "plugin.hpp" #include "plugin.hpp"
#include "util/util-logging.hpp"
#ifdef _DEBUG
#define ST_PREFIX "<%s> "
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#else
#define ST_PREFIX "<transition::shader> "
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
#endif
using namespace streamfx; using namespace streamfx;
#define ST_PREFIX "<gfx::lut::data> "
std::shared_ptr<streamfx::gfx::lut::data> streamfx::gfx::lut::data::instance() std::shared_ptr<streamfx::gfx::lut::data> streamfx::gfx::lut::data::instance()
{ {
static std::weak_ptr<streamfx::gfx::lut::data> _instance; static std::weak_ptr<streamfx::gfx::lut::data> _instance;
@ -53,7 +64,7 @@ streamfx::gfx::lut::data::data() : _producer_effect(), _consumer_effect()
try { try {
_producer_effect = std::make_shared<streamfx::obs::gs::effect>(lut_producer_path); _producer_effect = std::make_shared<streamfx::obs::gs::effect>(lut_producer_path);
} catch (std::exception const& ex) { } catch (std::exception const& ex) {
DLOG_ERROR(ST_PREFIX "Loading LUT Producer effect failed: %s", ex.what()); D_LOG_ERROR("Loading LUT Producer effect failed: %s", ex.what());
} }
} }
@ -62,7 +73,7 @@ streamfx::gfx::lut::data::data() : _producer_effect(), _consumer_effect()
try { try {
_consumer_effect = std::make_shared<streamfx::obs::gs::effect>(lut_consumer_path); _consumer_effect = std::make_shared<streamfx::obs::gs::effect>(lut_consumer_path);
} catch (std::exception const& ex) { } catch (std::exception const& ex) {
DLOG_ERROR(ST_PREFIX "Loading LUT Consumer effect failed: %s", ex.what()); D_LOG_ERROR("Loading LUT Consumer effect failed: %s", ex.what());
} }
} }
} }

View file

@ -20,15 +20,20 @@
#include "ui-updater.hpp" #include "ui-updater.hpp"
#include "common.hpp" #include "common.hpp"
#include "util/util-logging.hpp"
#define ST_PREFIX "<ui::updater> "
#define D_LOG_ERROR(...) DLOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) DLOG_WARNING(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) DLOG_INFO(ST_PREFIX __VA_ARGS__)
#ifdef _DEBUG #ifdef _DEBUG
#define D_LOG_DEBUG(...) DLOG_DEBUG(ST_PREFIX __VA_ARGS__) #define ST_PREFIX "<%s> "
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#else #else
#define D_LOG_DEBUG(...) #define ST_PREFIX "<ui::updater> "
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
#endif #endif
#define D_I18N_MENU_CHECKFORUPDATES "UI.Updater.Menu.CheckForUpdates" #define D_I18N_MENU_CHECKFORUPDATES "UI.Updater.Menu.CheckForUpdates"

View file

@ -24,22 +24,27 @@
#include <string_view> #include <string_view>
#include "configuration.hpp" #include "configuration.hpp"
#include "plugin.hpp" #include "plugin.hpp"
#include "util/util-logging.hpp"
#ifdef _DEBUG
#define ST_PREFIX "<%s> "
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#else
#define ST_PREFIX "<updater> "
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
#endif
// TODO: // TODO:
// - Cache result in the configuration directory (not as a configuration value). // - Cache result in the configuration directory (not as a configuration value).
// - Move 'autoupdater.last_checked_at' to out of the configuration. // - Move 'autoupdater.last_checked_at' to out of the configuration.
// - Figure out if nightly updates are viable at all. // - Figure out if nightly updates are viable at all.
#define ST_PREFIX "<updater> "
#define D_LOG_ERROR(...) DLOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) DLOG_WARNING(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) DLOG_INFO(ST_PREFIX __VA_ARGS__)
#ifdef _DEBUG
#define D_LOG_DEBUG(...) DLOG_DEBUG(ST_PREFIX __VA_ARGS__)
#else
#define D_LOG_DEBUG(...)
#endif
#define ST_CFG_GDPR "updater.gdpr" #define ST_CFG_GDPR "updater.gdpr"
#define ST_CFG_AUTOMATION "updater.automation" #define ST_CFG_AUTOMATION "updater.automation"
#define ST_CFG_CHANNEL "updater.channel" #define ST_CFG_CHANNEL "updater.channel"
@ -212,7 +217,7 @@ try {
info.version_patch, info.url.c_str()); info.version_patch, info.url.c_str());
} }
} else { } else {
D_LOG_DEBUG("No update available."); D_LOG_DEBUG("No update available.", "");
} }
// Notify listeners of the update. // Notify listeners of the update.
@ -258,7 +263,7 @@ void streamfx::updater::task_query(std::vector<char>& buffer)
buffer.reserve(0xFFFF); buffer.reserve(0xFFFF);
// Finally, execute the request. // Finally, execute the request.
D_LOG_DEBUG("Querying for latest releases..."); D_LOG_DEBUG("Querying for latest releases...", "");
if (CURLcode res = curl.perform(); res != CURLE_OK) { if (CURLcode res = curl.perform(); res != CURLE_OK) {
D_LOG_ERROR("Performing query failed with error: %s", curl_easy_strerror(res)); D_LOG_ERROR("Performing query failed with error: %s", curl_easy_strerror(res));
throw std::runtime_error(curl_easy_strerror(res)); throw std::runtime_error(curl_easy_strerror(res));
@ -370,7 +375,7 @@ streamfx::updater::updater()
_current_info.version_index = static_cast<uint16_t>(strtoul(&suffix.at(1), nullptr, 10)); _current_info.version_index = static_cast<uint16_t>(strtoul(&suffix.at(1), nullptr, 10));
} }
} catch (...) { } catch (...) {
D_LOG_ERROR("Failed to parse current version information, results may be inaccurate."); D_LOG_ERROR("Failed to parse current version information, results may be inaccurate.", "");
} }
} }

View file

@ -20,8 +20,21 @@
#include "util-threadpool.hpp" #include "util-threadpool.hpp"
#include "common.hpp" #include "common.hpp"
#include <cstddef> #include <cstddef>
#include "util/util-logging.hpp"
#ifdef _DEBUG
#define ST_PREFIX "<%s> "
#define D_LOG_ERROR(x, ...) P_LOG_ERROR(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_WARNING(x, ...) P_LOG_WARN(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_INFO(x, ...) P_LOG_INFO(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#define D_LOG_DEBUG(x, ...) P_LOG_DEBUG(ST_PREFIX##x, __FUNCTION_SIG__, __VA_ARGS__)
#else
#define ST_PREFIX "<util::threadpool> " #define ST_PREFIX "<util::threadpool> "
#define D_LOG_ERROR(...) P_LOG_ERROR(ST_PREFIX __VA_ARGS__)
#define D_LOG_WARNING(...) P_LOG_WARN(ST_PREFIX __VA_ARGS__)
#define D_LOG_INFO(...) P_LOG_INFO(ST_PREFIX __VA_ARGS__)
#define D_LOG_DEBUG(...) P_LOG_DEBUG(ST_PREFIX __VA_ARGS__)
#endif
// Most Tasks likely wait for IO, so we can use that time for other tasks. // Most Tasks likely wait for IO, so we can use that time for other tasks.
#define ST_CONCURRENCY_MULTIPLIER 2 #define ST_CONCURRENCY_MULTIPLIER 2
@ -103,13 +116,13 @@ void streamfx::util::threadpool::work()
try { try {
local_work->_callback(local_work->_data); local_work->_callback(local_work->_data);
} catch (std::exception const& ex) { } catch (std::exception const& ex) {
DLOG_WARNING(ST_PREFIX "Worker %" PRIx32 " caught exception from task (%" PRIxPTR ", %" PRIxPTR D_LOG_WARNING("Worker %" PRIx32 " caught exception from task (%" PRIxPTR ", %" PRIxPTR
") with message: %s", ") with message: %s",
local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()), local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()),
reinterpret_cast<ptrdiff_t>(local_work->_data.get()), ex.what()); reinterpret_cast<ptrdiff_t>(local_work->_data.get()), ex.what());
} catch (...) { } catch (...) {
DLOG_WARNING(ST_PREFIX "Worker %" PRIx32 " caught exception of unknown type from task (%" PRIxPTR D_LOG_WARNING("Worker %" PRIx32 " caught exception of unknown type from task (%" PRIxPTR ", %" PRIxPTR
", %" PRIxPTR ").", ").",
local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()), local_number, reinterpret_cast<ptrdiff_t>(local_work->_callback.target<void>()),
reinterpret_cast<ptrdiff_t>(local_work->_data.get())); reinterpret_cast<ptrdiff_t>(local_work->_data.get()));
} }