From 380d75f770c16e3726bb9df624da8a06345af501 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Tue, 7 Sep 2021 04:29:41 +0200 Subject: [PATCH] project: Unify logging structure --- source/gfx/lut/gfx-lut.cpp | 23 +++++++++++++++++------ source/ui/ui-updater.cpp | 17 +++++++++++------ source/updater.cpp | 31 ++++++++++++++++++------------- source/util/util-threadpool.cpp | 29 +++++++++++++++++++++-------- 4 files changed, 67 insertions(+), 33 deletions(-) diff --git a/source/gfx/lut/gfx-lut.cpp b/source/gfx/lut/gfx-lut.cpp index f6346666..1a06720f 100644 --- a/source/gfx/lut/gfx-lut.cpp +++ b/source/gfx/lut/gfx-lut.cpp @@ -19,16 +19,27 @@ // SOFTWARE. #include "gfx-lut.hpp" - #include - #include "obs/gs/gs-helper.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 " " +#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; -#define ST_PREFIX " " - std::shared_ptr streamfx::gfx::lut::data::instance() { static std::weak_ptr _instance; @@ -53,7 +64,7 @@ streamfx::gfx::lut::data::data() : _producer_effect(), _consumer_effect() try { _producer_effect = std::make_shared(lut_producer_path); } 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 { _consumer_effect = std::make_shared(lut_consumer_path); } 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()); } } } diff --git a/source/ui/ui-updater.cpp b/source/ui/ui-updater.cpp index 59adf2c7..1d9499d3 100644 --- a/source/ui/ui-updater.cpp +++ b/source/ui/ui-updater.cpp @@ -20,15 +20,20 @@ #include "ui-updater.hpp" #include "common.hpp" +#include "util/util-logging.hpp" -#define ST_PREFIX " " -#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__) +#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 D_LOG_DEBUG(...) +#define ST_PREFIX " " +#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 #define D_I18N_MENU_CHECKFORUPDATES "UI.Updater.Menu.CheckForUpdates" diff --git a/source/updater.cpp b/source/updater.cpp index 84d7b42d..c63e810f 100644 --- a/source/updater.cpp +++ b/source/updater.cpp @@ -24,22 +24,27 @@ #include #include "configuration.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 " " +#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: // - Cache result in the configuration directory (not as a configuration value). // - Move 'autoupdater.last_checked_at' to out of the configuration. // - Figure out if nightly updates are viable at all. -#define ST_PREFIX " " -#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_AUTOMATION "updater.automation" #define ST_CFG_CHANNEL "updater.channel" @@ -212,7 +217,7 @@ try { info.version_patch, info.url.c_str()); } } else { - D_LOG_DEBUG("No update available."); + D_LOG_DEBUG("No update available.", ""); } // Notify listeners of the update. @@ -258,7 +263,7 @@ void streamfx::updater::task_query(std::vector& buffer) buffer.reserve(0xFFFF); // 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) { D_LOG_ERROR("Performing query failed with error: %s", 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(strtoul(&suffix.at(1), nullptr, 10)); } } 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.", ""); } } diff --git a/source/util/util-threadpool.cpp b/source/util/util-threadpool.cpp index 766aaed6..8ddcb07c 100644 --- a/source/util/util-threadpool.cpp +++ b/source/util/util-threadpool.cpp @@ -20,8 +20,21 @@ #include "util-threadpool.hpp" #include "common.hpp" #include +#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 " " +#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. #define ST_CONCURRENCY_MULTIPLIER 2 @@ -103,15 +116,15 @@ void streamfx::util::threadpool::work() try { local_work->_callback(local_work->_data); } catch (std::exception const& ex) { - DLOG_WARNING(ST_PREFIX "Worker %" PRIx32 " caught exception from task (%" PRIxPTR ", %" PRIxPTR - ") with message: %s", - local_number, reinterpret_cast(local_work->_callback.target()), - reinterpret_cast(local_work->_data.get()), ex.what()); + D_LOG_WARNING("Worker %" PRIx32 " caught exception from task (%" PRIxPTR ", %" PRIxPTR + ") with message: %s", + local_number, reinterpret_cast(local_work->_callback.target()), + reinterpret_cast(local_work->_data.get()), ex.what()); } catch (...) { - DLOG_WARNING(ST_PREFIX "Worker %" PRIx32 " caught exception of unknown type from task (%" PRIxPTR - ", %" PRIxPTR ").", - local_number, reinterpret_cast(local_work->_callback.target()), - reinterpret_cast(local_work->_data.get())); + D_LOG_WARNING("Worker %" PRIx32 " caught exception of unknown type from task (%" PRIxPTR ", %" PRIxPTR + ").", + local_number, reinterpret_cast(local_work->_callback.target()), + reinterpret_cast(local_work->_data.get())); } }