refactor: use fmt (#2758)

* deps: use fmt (8.1.1 tag) to build log strings

Co-authored-by: Mike Gelfand <mikedld@mikedld.com>
This commit is contained in:
Charles Kerr
2022-03-13 23:43:35 -05:00
committed by GitHub
parent 2bd42f8225
commit a942c67199
44 changed files with 674 additions and 342 deletions

View File

@@ -130,6 +130,7 @@ include_directories(
)
include_directories(
SYSTEM
${LIBFMT_INCLUDE_DIRS}
${LIBAPPINDICATOR_INCLUDE_DIRS}
${GTK_INCLUDE_DIRS}
${CURL_INCLUDE_DIRS}
@@ -158,6 +159,7 @@ add_definitions(
-DPANGOMM_DISABLE_DEPRECATED
-DSIGCXX_DISABLE_DEPRECATED
${GTK_CFLAGS_OTHER}
${LIBFMT_DEFINITIONS}
)
tr_win32_app_info(${PROJECT_NAME}_WIN32_RC_FILE

View File

@@ -15,6 +15,8 @@
#include <event2/buffer.h>
#include <fmt/core.h>
#include <libtransmission/transmission.h>
#include <libtransmission/log.h>
@@ -1107,7 +1109,8 @@ void Session::Impl::add_file_async_callback(
{
if (!file->load_contents_finish(result, contents, length))
{
g_message(_("Couldn't read \"%s\""), file->get_parse_name().c_str());
auto const errmsg = fmt::format(_("Couldn't read '{path}'"), fmt::arg("path", file->get_parse_name().raw()));
g_message("%s", errmsg.c_str());
}
else if (tr_ctorSetMetainfo(ctor, contents, length, nullptr))
{
@@ -1120,7 +1123,12 @@ void Session::Impl::add_file_async_callback(
}
catch (Glib::Error const& e)
{
g_message(_("Couldn't read \"%s\": %s"), file->get_parse_name().c_str(), e.what().c_str());
auto const errmsg = fmt::format(
_("Couldn't read '{path}': {errmsg} ({errcode})"),
fmt::arg("path", file->get_parse_name().raw()),
fmt::arg("errmsg", e.what().raw()),
fmt::arg("errmsg", e.code()));
g_message("%s", errmsg.c_str());
}
dec_busy();
@@ -1437,13 +1445,13 @@ bool gtr_inhibit_hibernation(guint32& cookie)
cookie = Glib::VariantBase::cast_dynamic<Glib::Variant<guint32>>(response.get_child(0)).get();
/* logging */
tr_logAddInfo("%s", _("Inhibiting desktop hibernation"));
tr_logAddInfo(_("Inhibiting desktop hibernation"));
success = true;
}
catch (Glib::Error const& e)
{
tr_logAddError(_("Couldn't inhibit desktop hibernation: %s"), e.what().c_str());
tr_logAddError(fmt::format(_("Couldn't inhibit desktop hibernation: {errmsg}"), fmt::arg("errmsg", e.what().raw())));
}
return success;
@@ -1464,11 +1472,11 @@ void gtr_uninhibit_hibernation(guint inhibit_cookie)
1000);
/* logging */
tr_logAddInfo("%s", _("Allowing desktop hibernation"));
tr_logAddInfo(_("Allowing desktop hibernation"));
}
catch (Glib::Error const& e)
{
g_warning("Couldn't uninhibit desktop hibernation: %s.", e.what().c_str());
tr_logAddError(fmt::format(_("Couldn't inhibit desktop hibernation: {errmsg}"), fmt::arg("errmsg", e.what().raw())));
}
}