From 4bcb77defa2ef5a4b734ff1c6b21003d79e41976 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 7 Mar 2020 15:07:01 +0100 Subject: [PATCH] Add logging prefixes based on the plugin --- src/plugin/host-bridge.cpp | 22 +++++++++++++++++++++- src/wine-host/plugin-bridge.cpp | 26 +++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/plugin/host-bridge.cpp b/src/plugin/host-bridge.cpp index 46400991..69cd1c5c 100644 --- a/src/plugin/host-bridge.cpp +++ b/src/plugin/host-bridge.cpp @@ -29,6 +29,8 @@ // here. namespace bp = boost::process; +// I'd rather use std::filesystem instead, but Boost.Process depends on +// boost::filesystem namespace fs = boost::filesystem; /** @@ -42,6 +44,7 @@ constexpr auto yabridge_wine_host_name = "yabridge-host.exe"; constexpr char alphanumeric_characters[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; +std::string create_logger_prefix(const fs::path& socket_path); fs::path find_vst_plugin(); fs::path find_wine_vst_host(); fs::path generate_endpoint_name(); @@ -74,7 +77,8 @@ HostBridge::HostBridge(audioMasterCallback host_callback) host_vst_process_replacing(io_context), vst_host_aeffect(io_context), host_callback_function(host_callback), - logger(Logger::create_from_environment()), + logger(Logger::create_from_environment( + create_logger_prefix(socket_endpoint.path()))), vst_host(find_wine_vst_host(), // The Wine VST host needs to know which plugin to load // and which Unix domain socket to connect to @@ -229,6 +233,22 @@ fs::path find_wine_vst_host() { return vst_host_path; } +/** + * Create a logger prefix based on the unique socket path for easy + * identification. The socket path contains both the plugin's name and a unique + * identifier. + * + * @param socket_path The path to the socket endpoint in use. + * + * @return A prefix string for log messages. + */ +std::string create_logger_prefix(const fs::path& socket_path) { + std::ostringstream prefix; + prefix << "[" << socket_path.filename() << "] "; + + return prefix.str(); +} + /** * Find the VST plugin .dll file that corresponds to this copy of * `libyabridge.so`. This should be the same as the name of this file but with a diff --git a/src/wine-host/plugin-bridge.cpp b/src/wine-host/plugin-bridge.cpp index 0c2486df..416b5570 100644 --- a/src/wine-host/plugin-bridge.cpp +++ b/src/wine-host/plugin-bridge.cpp @@ -16,6 +16,10 @@ #include "plugin-bridge.h" +#include + +namespace fs = std::filesystem; + /** * A function pointer to what should be the entry point of a VST plugin. */ @@ -27,6 +31,8 @@ using VstEntryPoint = AEffect*(VST_CALL_CONV*)(audioMasterCallback); */ PluginBridge* current_bridge_isntance = nullptr; +std::string create_logger_prefix(const fs::path& socket_path); + intptr_t VST_CALL_CONV host_callback_proxy(AEffect*, int32_t, int32_t, intptr_t, void*, float); @@ -58,7 +64,8 @@ PluginBridge::PluginBridge(std::string plugin_dll_path, host_vst_parameters(io_context), host_vst_process_replacing(io_context), vst_host_aeffect(io_context), - logger(Logger::create_from_environment("[WINE] ")), + logger(Logger::create_from_environment( + create_logger_prefix(socket_endpoint_path))), process_buffer(std::make_unique()) { // Got to love these C APIs if (plugin_handle == nullptr) { @@ -192,6 +199,23 @@ intptr_t PluginBridge::host_callback(AEffect* /*plugin*/, return send_event(vst_host_callback, opcode, index, value, data, option); } +/** + * Create a logger prefix based on the unique socket path for easy + * identification. The socket path contains both the plugin's name and a unique + * identifier. + * + * @param socket_path The path to the socket endpoint in use. + * + * @return A prefix string for log messages. + */ +std::string create_logger_prefix(const fs::path& socket_path) { + std::ostringstream prefix; + prefix << "[" << socket_path.filename() << "] "; + prefix << "[WINE] "; + + return prefix.str(); +} + intptr_t VST_CALL_CONV host_callback_proxy(AEffect* effect, int32_t opcode, int32_t index,