mirror of https://github.com/djcb/mu.git
migrate to fmt-based logging in some more places
and improve logging.
This commit is contained in:
parent
4171fe14c3
commit
31f0c40893
|
@ -34,10 +34,6 @@
|
|||
|
||||
using namespace Mu;
|
||||
|
||||
constexpr uint8_t SepaChar1 = 0xfe;
|
||||
constexpr uint8_t SepaChar2 = 0xff;
|
||||
|
||||
|
||||
const Xapian::Document&
|
||||
Document::xapian_document() const
|
||||
{
|
||||
|
|
|
@ -256,12 +256,12 @@ public:
|
|||
|
||||
const auto strval = std::invoke([&]{
|
||||
if constexpr (prop.type == Type::Number || prop.type == Type::Timestamp)
|
||||
return format("%" PRIi64, static_cast<int64_t>(val));
|
||||
return mu_format("{}", static_cast<int64_t>(val));
|
||||
else if constexpr (prop.type == Type::Path || prop.type == Type::String)
|
||||
return std::string{val};
|
||||
else if constexpr (prop.type == Type::StringList)
|
||||
return join(val, SepaChar1);
|
||||
|
||||
else
|
||||
throw std::logic_error("invalid prop " + std::string{prop.name});
|
||||
});
|
||||
|
||||
|
@ -293,7 +293,6 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
static constexpr uint8_t SepaChar1 = 0xfe;
|
||||
MetadataIface& cstore_;
|
||||
};
|
||||
|
||||
|
|
|
@ -122,9 +122,6 @@ private:
|
|||
}
|
||||
};
|
||||
|
||||
constexpr auto Separator = "\xff"; // Invalid in UTF-8
|
||||
|
||||
|
||||
ContactUMap
|
||||
ContactsCache::Private::deserialize(const std::string& serialized) const
|
||||
{
|
||||
|
@ -133,7 +130,7 @@ ContactsCache::Private::deserialize(const std::string& serialized) const
|
|||
std::string line;
|
||||
|
||||
while (getline(ss, line)) {
|
||||
const auto parts = Mu::split(line, Separator);
|
||||
const auto parts = Mu::split(line, SepaChar2);
|
||||
if (G_UNLIKELY(parts.size() != 5)) {
|
||||
mu_warning("error: '{}'", line);
|
||||
continue;
|
||||
|
@ -168,20 +165,12 @@ ContactsCache::Private::serialize() const
|
|||
|
||||
for (auto& item : contacts_) {
|
||||
const auto& ci{item.second};
|
||||
s += Mu::format("%s%s"
|
||||
"%s%s"
|
||||
"%d%s"
|
||||
"%" G_GINT64_FORMAT "%s"
|
||||
"%" G_GINT64_FORMAT "\n",
|
||||
ci.email.c_str(),
|
||||
Separator,
|
||||
ci.name.c_str(),
|
||||
Separator,
|
||||
ci.personal ? 1 : 0,
|
||||
Separator,
|
||||
(gint64)ci.message_date,
|
||||
Separator,
|
||||
(gint64)ci.frequency);
|
||||
s += mu_format("{}{}{}{}{}{}{}{}{}\n",
|
||||
ci.email, SepaChar2,
|
||||
ci.name, SepaChar2,
|
||||
ci.personal ? 1 : 0, SepaChar2,
|
||||
ci.message_date, SepaChar2,
|
||||
ci.frequency);
|
||||
}
|
||||
config_db_.set<Config::Id::Contacts>(s);
|
||||
dirty_ = 0;
|
||||
|
|
|
@ -379,7 +379,6 @@ subject_matches(const std::string& sub1, const std::string& sub2)
|
|||
}
|
||||
};
|
||||
|
||||
// g_debug ("'%s' '%s'", search_str(sub1), search_str(sub2));
|
||||
return g_strcmp0(search_str(sub1), search_str(sub2)) == 0;
|
||||
}
|
||||
|
||||
|
@ -661,10 +660,10 @@ assert_thread_paths(const MockQueryResults& qrs, const Expected& expected)
|
|||
qr.path().value_or("") == exp.first;
|
||||
});
|
||||
g_assert_true(it != qrs.end());
|
||||
g_debug("thread-path (%s@%s): expected: '%s'; got '%s'",
|
||||
it->message_id().value_or("<none>").c_str(),
|
||||
it->path().value_or("<none>").c_str(),
|
||||
exp.second.c_str(), it->query_match().thread_path.c_str());
|
||||
mu_debug("thread-path ({}@{}): expected: '{}'; got '{}'",
|
||||
it->message_id().value_or("<none>"),
|
||||
it->path().value_or("<none>"),
|
||||
exp.second, it->query_match().thread_path);
|
||||
g_assert_cmpstr(exp.second.c_str(), ==, it->query_match().thread_path.c_str());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,10 +143,8 @@ Mu::run_script(const std::string& path,
|
|||
#else
|
||||
std::string mainargs;
|
||||
for (auto&& arg: args)
|
||||
mainargs += format("%s\"%s\"",
|
||||
mainargs.empty() ? "" : " ", arg.c_str());
|
||||
auto expr = format("(main '(\"%s\" %s))",
|
||||
get_name(path).c_str(), mainargs.c_str());
|
||||
mainargs += mu_format("{}\"{}\"", mainargs.empty() ? "" : " ", arg);
|
||||
auto expr = mu_format("(main '(\"{}\" {}))", get_name(path), mainargs);
|
||||
|
||||
std::vector<const char*> argv = {
|
||||
GUILE_BINARY,
|
||||
|
|
|
@ -46,6 +46,15 @@
|
|||
|
||||
namespace Mu {
|
||||
|
||||
|
||||
/*
|
||||
* Separator characters used in various places; importantly,
|
||||
* they are not used in UTF-8
|
||||
*/
|
||||
constexpr const auto SepaChar1 = '\xfe';
|
||||
constexpr const auto SepaChar2 = '\xff';
|
||||
|
||||
|
||||
/*
|
||||
* Logging/printing/formatting functions connect libfmt with the Glib logging
|
||||
* system. We wrap so perhaps at some point (C++23?) we can use std:: instead.
|
||||
|
@ -53,35 +62,38 @@ namespace Mu {
|
|||
|
||||
/*
|
||||
* Debug/error/warning logging
|
||||
*
|
||||
* The 'noexcept' means that they _wilL_ terminate the program
|
||||
* when the formatting fails (ie. a bug)
|
||||
*/
|
||||
|
||||
template<typename...T>
|
||||
inline void mu_debug(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_debug(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
g_log("mu", G_LOG_LEVEL_DEBUG, "%s",
|
||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||
}
|
||||
template<typename...T>
|
||||
inline void mu_info(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_info(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
g_log("mu", G_LOG_LEVEL_INFO, "%s",
|
||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||
}
|
||||
template<typename...T>
|
||||
inline void mu_message(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_message(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
g_log("mu", G_LOG_LEVEL_MESSAGE, "%s",
|
||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||
}
|
||||
template<typename...T>
|
||||
inline void mu_warning(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_warning(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
g_log("mu", G_LOG_LEVEL_WARNING, "%s",
|
||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||
}
|
||||
template<typename...T>
|
||||
inline void mu_critical(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_critical(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
g_log("mu", G_LOG_LEVEL_CRITICAL, "%s",
|
||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||
}
|
||||
template<typename...T>
|
||||
inline void mu_error(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_error(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
g_log("mu", G_LOG_LEVEL_ERROR, "%s",
|
||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||
}
|
||||
|
@ -91,19 +103,19 @@ inline void mu_error(fmt::format_string<T...> frm, T&&... args) noexcept {
|
|||
*/
|
||||
|
||||
template<typename...T>
|
||||
inline void mu_print(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_print(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
fmt::print(frm, std::forward<T>(args)...);
|
||||
}
|
||||
template<typename...T>
|
||||
inline void mu_println(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_println(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
fmt::println(frm, std::forward<T>(args)...);
|
||||
}
|
||||
template<typename...T>
|
||||
inline void mu_printerr(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_printerr(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
fmt::print(stderr, frm, std::forward<T>(args)...);
|
||||
}
|
||||
template<typename...T>
|
||||
inline void mu_printerrln(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
void mu_printerrln(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
fmt::println(stderr, frm, std::forward<T>(args)...);
|
||||
}
|
||||
|
||||
|
@ -112,10 +124,16 @@ inline void mu_printerrln(fmt::format_string<T...> frm, T&&... args) noexcept {
|
|||
* Fprmatting
|
||||
*/
|
||||
template<typename...T>
|
||||
inline std::string mu_format(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
std::string mu_format(fmt::format_string<T...> frm, T&&... args) noexcept {
|
||||
return fmt::format(frm, std::forward<T>(args)...);
|
||||
}
|
||||
|
||||
template<typename Range>
|
||||
auto mu_join(Range&& range, std::string_view sepa) {
|
||||
return fmt::join(std::forward<Range>(range), sepa);
|
||||
}
|
||||
|
||||
|
||||
using StringVec = std::vector<std::string>;
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,8 +30,7 @@ Mu::mu_cmd_add(Mu::Store& store, const Options& opts)
|
|||
if (!docid)
|
||||
return Err(docid.error());
|
||||
else
|
||||
g_debug("added message @ %s, docid=%u",
|
||||
file.c_str(), docid.value());
|
||||
mu_debug("added message @ {}, docid={}", file, *docid);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
|
|
|
@ -129,7 +129,8 @@ topic_fields(const Options& opts)
|
|||
});
|
||||
|
||||
colorify(fields, opts);
|
||||
std::cout << fields << '\n';
|
||||
|
||||
std::cout << "# Message fields\n" << fields << '\n';
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
@ -169,8 +170,7 @@ topic_flags(const Options& opts)
|
|||
|
||||
colorify(flags, opts);
|
||||
|
||||
std::cout << flags << '\n';
|
||||
|
||||
std::cout << "# Message flags\n" << flags << '\n';
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
@ -251,8 +251,6 @@ topic_mu(const Options& opts)
|
|||
|
||||
std::cout << info << '\n';
|
||||
|
||||
// mu_println("{}", info);
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
@ -268,6 +266,7 @@ Mu::mu_cmd_info(const Mu::Store& store, const Options& opts)
|
|||
return topic_store(store, opts);
|
||||
else if (topic == "fields") {
|
||||
topic_fields(opts);
|
||||
std::cout << std::endl;
|
||||
return topic_flags(opts);
|
||||
} else if (topic == "mu") {
|
||||
return topic_mu(opts);
|
||||
|
|
|
@ -30,7 +30,7 @@ Mu::mu_cmd_remove(Mu::Store& store, const Options& opts)
|
|||
if (!res)
|
||||
return Err(Error::Code::File, "failed to remove {}", file.c_str());
|
||||
else
|
||||
g_debug("removed message @ %s", file.c_str());
|
||||
mu_debug("removed message @ {}", file);
|
||||
}
|
||||
|
||||
return Ok();
|
||||
|
|
Loading…
Reference in New Issue