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;
|
using namespace Mu;
|
||||||
|
|
||||||
constexpr uint8_t SepaChar1 = 0xfe;
|
|
||||||
constexpr uint8_t SepaChar2 = 0xff;
|
|
||||||
|
|
||||||
|
|
||||||
const Xapian::Document&
|
const Xapian::Document&
|
||||||
Document::xapian_document() const
|
Document::xapian_document() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -256,13 +256,13 @@ public:
|
||||||
|
|
||||||
const auto strval = std::invoke([&]{
|
const auto strval = std::invoke([&]{
|
||||||
if constexpr (prop.type == Type::Number || prop.type == Type::Timestamp)
|
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)
|
else if constexpr (prop.type == Type::Path || prop.type == Type::String)
|
||||||
return std::string{val};
|
return std::string{val};
|
||||||
else if constexpr (prop.type == Type::StringList)
|
else if constexpr (prop.type == Type::StringList)
|
||||||
return join(val, SepaChar1);
|
return join(val, SepaChar1);
|
||||||
|
else
|
||||||
throw std::logic_error("invalid prop " + std::string{prop.name});
|
throw std::logic_error("invalid prop " + std::string{prop.name});
|
||||||
});
|
});
|
||||||
|
|
||||||
cstore_.set_metadata(std::string{prop.name}, strval);
|
cstore_.set_metadata(std::string{prop.name}, strval);
|
||||||
|
@ -293,7 +293,6 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr uint8_t SepaChar1 = 0xfe;
|
|
||||||
MetadataIface& cstore_;
|
MetadataIface& cstore_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -122,9 +122,6 @@ private:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr auto Separator = "\xff"; // Invalid in UTF-8
|
|
||||||
|
|
||||||
|
|
||||||
ContactUMap
|
ContactUMap
|
||||||
ContactsCache::Private::deserialize(const std::string& serialized) const
|
ContactsCache::Private::deserialize(const std::string& serialized) const
|
||||||
{
|
{
|
||||||
|
@ -133,7 +130,7 @@ ContactsCache::Private::deserialize(const std::string& serialized) const
|
||||||
std::string line;
|
std::string line;
|
||||||
|
|
||||||
while (getline(ss, 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)) {
|
if (G_UNLIKELY(parts.size() != 5)) {
|
||||||
mu_warning("error: '{}'", line);
|
mu_warning("error: '{}'", line);
|
||||||
continue;
|
continue;
|
||||||
|
@ -168,20 +165,12 @@ ContactsCache::Private::serialize() const
|
||||||
|
|
||||||
for (auto& item : contacts_) {
|
for (auto& item : contacts_) {
|
||||||
const auto& ci{item.second};
|
const auto& ci{item.second};
|
||||||
s += Mu::format("%s%s"
|
s += mu_format("{}{}{}{}{}{}{}{}{}\n",
|
||||||
"%s%s"
|
ci.email, SepaChar2,
|
||||||
"%d%s"
|
ci.name, SepaChar2,
|
||||||
"%" G_GINT64_FORMAT "%s"
|
ci.personal ? 1 : 0, SepaChar2,
|
||||||
"%" G_GINT64_FORMAT "\n",
|
ci.message_date, SepaChar2,
|
||||||
ci.email.c_str(),
|
ci.frequency);
|
||||||
Separator,
|
|
||||||
ci.name.c_str(),
|
|
||||||
Separator,
|
|
||||||
ci.personal ? 1 : 0,
|
|
||||||
Separator,
|
|
||||||
(gint64)ci.message_date,
|
|
||||||
Separator,
|
|
||||||
(gint64)ci.frequency);
|
|
||||||
}
|
}
|
||||||
config_db_.set<Config::Id::Contacts>(s);
|
config_db_.set<Config::Id::Contacts>(s);
|
||||||
dirty_ = 0;
|
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;
|
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;
|
qr.path().value_or("") == exp.first;
|
||||||
});
|
});
|
||||||
g_assert_true(it != qrs.end());
|
g_assert_true(it != qrs.end());
|
||||||
g_debug("thread-path (%s@%s): expected: '%s'; got '%s'",
|
mu_debug("thread-path ({}@{}): expected: '{}'; got '{}'",
|
||||||
it->message_id().value_or("<none>").c_str(),
|
it->message_id().value_or("<none>"),
|
||||||
it->path().value_or("<none>").c_str(),
|
it->path().value_or("<none>"),
|
||||||
exp.second.c_str(), it->query_match().thread_path.c_str());
|
exp.second, it->query_match().thread_path);
|
||||||
g_assert_cmpstr(exp.second.c_str(), ==, it->query_match().thread_path.c_str());
|
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
|
#else
|
||||||
std::string mainargs;
|
std::string mainargs;
|
||||||
for (auto&& arg: args)
|
for (auto&& arg: args)
|
||||||
mainargs += format("%s\"%s\"",
|
mainargs += mu_format("{}\"{}\"", mainargs.empty() ? "" : " ", arg);
|
||||||
mainargs.empty() ? "" : " ", arg.c_str());
|
auto expr = mu_format("(main '(\"{}\" {}))", get_name(path), mainargs);
|
||||||
auto expr = format("(main '(\"%s\" %s))",
|
|
||||||
get_name(path).c_str(), mainargs.c_str());
|
|
||||||
|
|
||||||
std::vector<const char*> argv = {
|
std::vector<const char*> argv = {
|
||||||
GUILE_BINARY,
|
GUILE_BINARY,
|
||||||
|
|
|
@ -46,6 +46,15 @@
|
||||||
|
|
||||||
namespace Mu {
|
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
|
* 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.
|
* 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
|
* Debug/error/warning logging
|
||||||
|
*
|
||||||
|
* The 'noexcept' means that they _wilL_ terminate the program
|
||||||
|
* when the formatting fails (ie. a bug)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
template<typename...T>
|
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",
|
g_log("mu", G_LOG_LEVEL_DEBUG, "%s",
|
||||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||||
}
|
}
|
||||||
template<typename...T>
|
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",
|
g_log("mu", G_LOG_LEVEL_INFO, "%s",
|
||||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||||
}
|
}
|
||||||
template<typename...T>
|
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",
|
g_log("mu", G_LOG_LEVEL_MESSAGE, "%s",
|
||||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||||
}
|
}
|
||||||
template<typename...T>
|
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",
|
g_log("mu", G_LOG_LEVEL_WARNING, "%s",
|
||||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||||
}
|
}
|
||||||
template<typename...T>
|
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",
|
g_log("mu", G_LOG_LEVEL_CRITICAL, "%s",
|
||||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
fmt::format(frm, std::forward<T>(args)...).c_str());
|
||||||
}
|
}
|
||||||
template<typename...T>
|
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",
|
g_log("mu", G_LOG_LEVEL_ERROR, "%s",
|
||||||
fmt::format(frm, std::forward<T>(args)...).c_str());
|
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>
|
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)...);
|
fmt::print(frm, std::forward<T>(args)...);
|
||||||
}
|
}
|
||||||
template<typename...T>
|
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)...);
|
fmt::println(frm, std::forward<T>(args)...);
|
||||||
}
|
}
|
||||||
template<typename...T>
|
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)...);
|
fmt::print(stderr, frm, std::forward<T>(args)...);
|
||||||
}
|
}
|
||||||
template<typename...T>
|
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)...);
|
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
|
* Fprmatting
|
||||||
*/
|
*/
|
||||||
template<typename...T>
|
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)...);
|
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>;
|
using StringVec = std::vector<std::string>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -30,8 +30,7 @@ Mu::mu_cmd_add(Mu::Store& store, const Options& opts)
|
||||||
if (!docid)
|
if (!docid)
|
||||||
return Err(docid.error());
|
return Err(docid.error());
|
||||||
else
|
else
|
||||||
g_debug("added message @ %s, docid=%u",
|
mu_debug("added message @ {}, docid={}", file, *docid);
|
||||||
file.c_str(), docid.value());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
|
|
|
@ -129,7 +129,8 @@ topic_fields(const Options& opts)
|
||||||
});
|
});
|
||||||
|
|
||||||
colorify(fields, opts);
|
colorify(fields, opts);
|
||||||
std::cout << fields << '\n';
|
|
||||||
|
std::cout << "# Message fields\n" << fields << '\n';
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
@ -169,8 +170,7 @@ topic_flags(const Options& opts)
|
||||||
|
|
||||||
colorify(flags, opts);
|
colorify(flags, opts);
|
||||||
|
|
||||||
std::cout << flags << '\n';
|
std::cout << "# Message flags\n" << flags << '\n';
|
||||||
|
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
@ -251,8 +251,6 @@ topic_mu(const Options& opts)
|
||||||
|
|
||||||
std::cout << info << '\n';
|
std::cout << info << '\n';
|
||||||
|
|
||||||
// mu_println("{}", info);
|
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,6 +266,7 @@ Mu::mu_cmd_info(const Mu::Store& store, const Options& opts)
|
||||||
return topic_store(store, opts);
|
return topic_store(store, opts);
|
||||||
else if (topic == "fields") {
|
else if (topic == "fields") {
|
||||||
topic_fields(opts);
|
topic_fields(opts);
|
||||||
|
std::cout << std::endl;
|
||||||
return topic_flags(opts);
|
return topic_flags(opts);
|
||||||
} else if (topic == "mu") {
|
} else if (topic == "mu") {
|
||||||
return topic_mu(opts);
|
return topic_mu(opts);
|
||||||
|
|
|
@ -30,7 +30,7 @@ Mu::mu_cmd_remove(Mu::Store& store, const Options& opts)
|
||||||
if (!res)
|
if (!res)
|
||||||
return Err(Error::Code::File, "failed to remove {}", file.c_str());
|
return Err(Error::Code::File, "failed to remove {}", file.c_str());
|
||||||
else
|
else
|
||||||
g_debug("removed message @ %s", file.c_str());
|
mu_debug("removed message @ {}", file);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
|
|
Loading…
Reference in New Issue