mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-11 07:10:36 +00:00
format systemd status as time deltas from now
This commit is contained in:
parent
18e1272c76
commit
60ada470db
@ -870,10 +870,11 @@ namespace llarp
|
||||
<< NumberOfConnectedRouters() << "/" << NumberOfConnectedClients() << " | "
|
||||
<< pathContext().CurrentTransitPaths() << " active paths | "
|
||||
<< "block " << (m_lokidRpcClient ? m_lokidRpcClient->BlockHeight() : 0) << " | gossip: "
|
||||
<< "(next/last) " << _rcGossiper.NextGossipAt() << "/";
|
||||
<< "(next/last) " << time_delta<std::chrono::seconds>{_rcGossiper.NextGossipAt()}
|
||||
<< " / ";
|
||||
if (auto maybe = _rcGossiper.LastGossipAt())
|
||||
{
|
||||
ss << *maybe;
|
||||
ss << time_delta<std::chrono::seconds>{*maybe};
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -29,4 +29,33 @@ namespace llarp
|
||||
std::ostream&
|
||||
operator<<(std::ostream& out, const TimePoint_t& t);
|
||||
|
||||
template <typename Time_Duration>
|
||||
struct time_delta
|
||||
{
|
||||
const TimePoint_t at;
|
||||
|
||||
std::ostream&
|
||||
operator()(std::ostream& out) const
|
||||
{
|
||||
const auto dlt = std::chrono::duration_cast<Time_Duration>(TimePoint_t::clock::now() - at);
|
||||
if (dlt > 0s)
|
||||
return out << std::chrono::duration_cast<Duration_t>(dlt) << " ago ";
|
||||
else if (dlt < 0s)
|
||||
return out << "in " << std::chrono::duration_cast<Duration_t>(-dlt);
|
||||
else
|
||||
return out << "now";
|
||||
}
|
||||
};
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& out, const time_delta<std::chrono::seconds>& td)
|
||||
{
|
||||
return td(out);
|
||||
}
|
||||
|
||||
inline std::ostream&
|
||||
operator<<(std::ostream& out, const time_delta<std::chrono::milliseconds>& td)
|
||||
{
|
||||
return td(out);
|
||||
}
|
||||
} // namespace llarp
|
||||
|
Loading…
Reference in New Issue
Block a user