Improve logging formatting

This commit is contained in:
Robbert van der Helm
2020-03-07 23:09:58 +01:00
parent 80ed96acd7
commit 5d96f9e13b
2 changed files with 40 additions and 35 deletions
+35 -30
View File
@@ -27,7 +27,7 @@ constexpr char logging_file_environment_variable[] = "YABRIDGE_DEBUG_FILE";
constexpr char logging_verbosity_environment_variable[] = constexpr char logging_verbosity_environment_variable[] =
"YABRIDGE_DEBUG_LEVEL"; "YABRIDGE_DEBUG_LEVEL";
std::optional<std::string> opcode_to_string(int opcode, bool dispatch); std::optional<std::string> opcode_to_string(bool is_dispatch, int opcode);
Logger::Logger(std::shared_ptr<std::ostream> stream, Logger::Logger(std::shared_ptr<std::ostream> stream,
Verbosity verbosity_level, Verbosity verbosity_level,
@@ -87,7 +87,7 @@ void Logger::log(const std::string& message) {
void Logger::log_get_parameter(int32_t index) { void Logger::log_get_parameter(int32_t index) {
if (verbosity >= Verbosity::events) { if (verbosity >= Verbosity::events) {
std::ostringstream message; std::ostringstream message;
message << "> getParameter() " << index; message << ">> getParameter() " << index;
log(message.str()); 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) { void Logger::log_get_parameter_response(int32_t index, float value) {
if (verbosity >= Verbosity::events) { if (verbosity >= Verbosity::events) {
std::ostringstream message; std::ostringstream message;
message << "< getParameter() " << index << " == " << value; message << " getParameter() :: " << index << " == " << value;
log(message.str()); 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) { void Logger::log_set_parameter(int32_t index, float value) {
if (verbosity >= Verbosity::events) { if (verbosity >= Verbosity::events) {
std::ostringstream message; std::ostringstream message;
message << "> setParameter() " << index << " = " << value; message << ">> setParameter() " << index << " = " << value;
log(message.str()); 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) { void Logger::log_set_parameter_response(int32_t index) {
if (verbosity >= Verbosity::events) { if (verbosity >= Verbosity::events) {
std::ostringstream message; std::ostringstream message;
message << "< setParameter() " << index << " OK"; message << " setParameter() :: " << index << " OK";
log(message.str()); log(message.str());
} }
} }
void Logger::log_event(bool dispatch, void Logger::log_event(bool is_dispatch,
int32_t opcode, int32_t opcode,
int32_t index, int32_t index,
intptr_t value, intptr_t value,
std::optional<std::string> data, std::optional<std::string> payload,
float option) { float option) {
if (verbosity >= Verbosity::events) { if (verbosity >= Verbosity::events) {
std::ostringstream message; std::ostringstream message;
if (dispatch) { if (is_dispatch) {
message << "> dispatch() "; message << ">> dispatch() ";
} else { } 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 << "<opcode = " << opcode << ">";
} }
message
<< opcode_to_string(opcode, dispatch).value_or("<unknown_event>");
message << "(index = " << index << ", value = " << value message << "(index = " << index << ", value = " << value
<< ", option = " << option << ", data = "; << ", option = " << option << ", data = ";
if (!payload.has_value()) {
if (!data.has_value()) {
message << "<nullptr>"; message << "<nullptr>";
} else if (data->empty()) { } else if (payload->empty()) {
message << "<writable_buffer>"; message << "<writable_buffer>";
} else { } else {
// Might print binary data, maybe check for this? // Might print binary payload, maybe check for this?
message << data.value(); message << "\"" << payload.value() << "\"";
} }
message << ")"; message << ")";
log(message.str()); log(message.str());
} }
} }
void Logger::log_event_response(bool dispatch, void Logger::log_event_response(bool is_dispatch,
intptr_t return_value, intptr_t return_value,
std::optional<std::string> data) { std::optional<std::string> payload) {
if (verbosity >= Verbosity::events) { if (verbosity >= Verbosity::events) {
std::ostringstream message; std::ostringstream message;
if (dispatch) { if (is_dispatch) {
message << "< dispatch() "; message << " dispatch() :: ";
} else { } else {
message << "< audioMasterCallback() "; message << " audioMasterCallback() :: ";
} }
message << " " << return_value; message << return_value;
if (data.has_value()) { if (payload.has_value()) {
message << ", " << data.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. * 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. * 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 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 * @return Either the name from `aeffect.h`, or a nullopt if it was not listed
* there. * there.
*/ */
std::optional<std::string> opcode_to_string(int opcode, bool dispatch) { std::optional<std::string> opcode_to_string(bool is_dispatch, int opcode) {
if (dispatch) { if (is_dispatch) {
// Opcodes for a plugin's dispatch function // Opcodes for a plugin's dispatch function
switch (opcode) { switch (opcode) {
case effOpen: case effOpen:
+5 -5
View File
@@ -92,17 +92,17 @@ class Logger {
void log_get_parameter_response(int32_t index, float vlaue); void log_get_parameter_response(int32_t index, float vlaue);
void log_set_parameter(int32_t index, float value); void log_set_parameter(int32_t index, float value);
void log_set_parameter_response(int32_t index); 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. // 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 opcode,
int32_t index, int32_t index,
intptr_t value, intptr_t value,
std::optional<std::string> data, std::optional<std::string> payload,
float option); float option);
void log_event_response(bool dispatch, void log_event_response(bool is_dispatch,
intptr_t return_value, intptr_t return_value,
std::optional<std::string> data); std::optional<std::string> payload);
private: private:
/** /**