Skip to content

Commit

Permalink
Refactored some function to use libfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mauer committed Nov 30, 2023
1 parent a53fa1c commit 5ef83dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/common/midi_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include "midi_message.h"

// fmt
#include "fmt/format.h"

// XMidiCtrl
#include "conversions.h"

Expand Down Expand Up @@ -130,7 +133,7 @@ bool midi_message::check()
return false;

case midi_msg_type::none:
m_log->error("Could not determine MIDI type from Status '" + std::to_string(m_status) + "'");
m_log->error(fmt::format("Could not determine MIDI type from Status '{}'", m_status));
return false;

default:
Expand Down
17 changes: 6 additions & 11 deletions src/common/text_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void text_logger::enable_file_logging(const std::filesystem::path& in_path)

m_file_stream.open(filename, std::ios_base::out | std::ios_base::trunc);
if (!m_file_stream.is_open())
error("Failed to open log file '" + filename + "'");
error(fmt::format("Failed to open log file '{}'", filename));
} else {
error("Cannot open log file as the give file path is empty");
}
Expand Down Expand Up @@ -209,9 +209,7 @@ void text_logger::debug(std::string_view in_text)
*/
void text_logger::debug_line(std::uint_least32_t in_line, std::string_view in_text)
{
std::string debug_text = " --> Line " + std::to_string(in_line) + " :: " + std::string(in_text);

debug(debug_text);
debug(fmt::format(" --> Line {} :: {}", in_line, in_text));
}


Expand All @@ -220,7 +218,7 @@ void text_logger::debug_line(std::uint_least32_t in_line, std::string_view in_te
*/
void text_logger::debug_param(std::uint_least32_t in_line, std::string_view in_param, std::string_view in_value)
{
debug_line(in_line, "Parameter '" + std::string(in_param) + "' = '" + std::string(in_value) + "'");
debug_line(in_line, fmt::format("Parameter '{}' = '{}'", in_param, in_value));
}


Expand Down Expand Up @@ -253,10 +251,7 @@ void text_logger::warn(std::string_view in_text)
*/
void text_logger::warn_line(std::uint_least32_t in_line, std::string_view in_text)
{
//std::string warn_text = " --> Line " + std::to_string(in_line) + " :: " + std::string(in_text);
std::string warn_text = fmt::format(" --> Line {} :: {}", in_line, in_text);

warn(warn_text);
warn(fmt::format(" --> Line {} :: {}", in_line, in_text));
}


Expand All @@ -277,7 +272,7 @@ void text_logger::error(std::string_view in_text)
*/
void text_logger::error_line(std::uint_least32_t in_line, std::string_view in_text)
{
std::string debug_text = " --> Line " + std::to_string(in_line) + " :: " + std::string(in_text);
std::string debug_text = fmt::format(" --> Line {} :: {}", in_line, in_text);

create_message(log_level::error, debug_text);

Expand Down Expand Up @@ -390,4 +385,4 @@ void text_logger::add_message(log_level in_level, std::string_view in_text)
}
}

} // Namespace xmidictrl
} // Namespace xmidictrl
5 changes: 4 additions & 1 deletion src/env/xplane/cmd_xplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

#include "cmd_xplane.h"

// fmt
#include "fmt/format.h"

namespace xmidictrl {

//---------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -81,7 +84,7 @@ XPLMCommandRef cmd_xplane::find_command_ref(text_logger &in_log, std::string_vie
}

if (cmd_ref == nullptr)
in_log.error("Command '" + std::string(in_cmd) + "' not found");
in_log.error(fmt::format("Command '{}' not found", in_cmd));

return cmd_ref;
}
Expand Down

0 comments on commit 5ef83dd

Please sign in to comment.