From 5d96f9e13b6e171b6ae0af1b8149c09bf7a2fc0b Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 7 Mar 2020 23:09:58 +0100 Subject: [PATCH] Improve logging formatting --- src/common/logging.cpp | 65 +++++++++++++++++++++++------------------- src/common/logging.h | 10 +++---- 2 files changed, 40 insertions(+), 35 deletions(-) diff --git a/src/common/logging.cpp b/src/common/logging.cpp index 10ac9179..962abedf 100644 --- a/src/common/logging.cpp +++ b/src/common/logging.cpp @@ -27,7 +27,7 @@ constexpr char logging_file_environment_variable[] = "YABRIDGE_DEBUG_FILE"; constexpr char logging_verbosity_environment_variable[] = "YABRIDGE_DEBUG_LEVEL"; -std::optional opcode_to_string(int opcode, bool dispatch); +std::optional opcode_to_string(bool is_dispatch, int opcode); Logger::Logger(std::shared_ptr stream, Verbosity verbosity_level, @@ -87,7 +87,7 @@ void Logger::log(const std::string& message) { void Logger::log_get_parameter(int32_t index) { if (verbosity >= Verbosity::events) { std::ostringstream message; - message << "> getParameter() " << index; + message << ">> getParameter() " << index; log(message.str()); } @@ -96,7 +96,7 @@ void Logger::log_get_parameter(int32_t index) { void Logger::log_get_parameter_response(int32_t index, float value) { if (verbosity >= Verbosity::events) { std::ostringstream message; - message << "< getParameter() " << index << " == " << value; + message << " getParameter() :: " << index << " == " << value; log(message.str()); } @@ -105,7 +105,7 @@ void Logger::log_get_parameter_response(int32_t index, float value) { void Logger::log_set_parameter(int32_t index, float value) { if (verbosity >= Verbosity::events) { std::ostringstream message; - message << "> setParameter() " << index << " = " << value; + message << ">> setParameter() " << index << " = " << value; log(message.str()); } @@ -114,61 +114,66 @@ void Logger::log_set_parameter(int32_t index, float value) { void Logger::log_set_parameter_response(int32_t index) { if (verbosity >= Verbosity::events) { std::ostringstream message; - message << "< setParameter() " << index << " OK"; + message << " setParameter() :: " << index << " OK"; log(message.str()); } } -void Logger::log_event(bool dispatch, +void Logger::log_event(bool is_dispatch, int32_t opcode, int32_t index, intptr_t value, - std::optional data, + std::optional payload, float option) { if (verbosity >= Verbosity::events) { std::ostringstream message; - if (dispatch) { - message << "> dispatch() "; + if (is_dispatch) { + message << ">> dispatch() "; } else { - message << "> audioMasterCallback() "; + message << ">> audioMasterCallback() "; + } + + const auto opcode_name = opcode_to_string(is_dispatch, opcode); + if (opcode_name.has_value()) { + message << opcode_name.value(); + } else { + message << ""; } - message - << opcode_to_string(opcode, dispatch).value_or(""); message << "(index = " << index << ", value = " << value << ", option = " << option << ", data = "; - - if (!data.has_value()) { + if (!payload.has_value()) { message << ""; - } else if (data->empty()) { + } else if (payload->empty()) { message << ""; } else { - // Might print binary data, maybe check for this? - message << data.value(); + // Might print binary payload, maybe check for this? + message << "\"" << payload.value() << "\""; } - message << ")"; log(message.str()); } } -void Logger::log_event_response(bool dispatch, +void Logger::log_event_response(bool is_dispatch, intptr_t return_value, - std::optional data) { + std::optional payload) { if (verbosity >= Verbosity::events) { std::ostringstream message; - if (dispatch) { - message << "< dispatch() "; + if (is_dispatch) { + message << " dispatch() :: "; } else { - message << "< audioMasterCallback() "; + message << " audioMasterCallback() :: "; } - message << " " << return_value; - if (data.has_value()) { - message << ", " << data.value(); + message << return_value; + if (payload.has_value()) { + message << ", \"" << payload.value() << "\""; } + + log(message.str()); } } @@ -176,15 +181,15 @@ void Logger::log_event_response(bool dispatch, * Convert an event opcode to a human readable string for debugging purposes. * See `src/include/vestige/aeffect.h` for a complete list of these opcodes. * + * @param is_dispatch Whether to use opcodes for the `dispatch` function. Will + * use the names from the host callback function if set to false. * @param opcode The opcode of the event. - * @param dispatch Whether to use opcodes for the `dispatch` function. Will use - * the names from the host callback function if set to false. * * @return Either the name from `aeffect.h`, or a nullopt if it was not listed * there. */ -std::optional opcode_to_string(int opcode, bool dispatch) { - if (dispatch) { +std::optional opcode_to_string(bool is_dispatch, int opcode) { + if (is_dispatch) { // Opcodes for a plugin's dispatch function switch (opcode) { case effOpen: diff --git a/src/common/logging.h b/src/common/logging.h index e5f37eb1..938a7ae0 100644 --- a/src/common/logging.h +++ b/src/common/logging.h @@ -92,17 +92,17 @@ class Logger { void log_get_parameter_response(int32_t index, float vlaue); void log_set_parameter(int32_t index, float value); void log_set_parameter_response(int32_t index); - // If dispatch is true, then use opcode names from the plugin's dispatch + // If is_dispatch is true, then use opcode names from the plugin's dispatch // function. Otherwise use names for the host callback function opcodes. - void log_event(bool dispatch, + void log_event(bool is_dispatch, int32_t opcode, int32_t index, intptr_t value, - std::optional data, + std::optional payload, float option); - void log_event_response(bool dispatch, + void log_event_response(bool is_dispatch, intptr_t return_value, - std::optional data); + std::optional payload); private: /**