mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-03-12 09:29:51 +00:00
Added log padding
This commit is contained in:
parent
0818d91f4f
commit
2e2bd1d137
3 changed files with 58 additions and 6 deletions
37
src/log.h
37
src/log.h
|
@ -414,6 +414,43 @@ template<> struct log::Stream::Entry<Duration>
|
|||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct PadRight
|
||||
{
|
||||
FORCEINLINE PadRight(const T& value, int len) : m_value(value), m_len(len) {}
|
||||
|
||||
const T& m_value;
|
||||
int m_len;
|
||||
|
||||
// Declare it to make compiler happy
|
||||
PadRight(const PadRight&);
|
||||
|
||||
private:
|
||||
PadRight& operator=(const PadRight&) = delete;
|
||||
PadRight& operator=(PadRight&&) = delete;
|
||||
};
|
||||
|
||||
template<typename T> FORCEINLINE PadRight<T> pad_right(const T& value, int len) { return PadRight<T>(value, len); }
|
||||
|
||||
template<typename T>
|
||||
struct log::Stream::Entry<PadRight<T>>
|
||||
{
|
||||
static NOINLINE void put(PadRight<T>&& data, Stream* wrapper)
|
||||
{
|
||||
char buf[log::Stream::BUF_SIZE + 1];
|
||||
log::Stream s(buf);
|
||||
s << data.m_value;
|
||||
|
||||
const int len = std::min<int>(data.m_len, log::Stream::BUF_SIZE);
|
||||
if (s.m_pos < len) {
|
||||
memset(buf + s.m_pos, ' ', len - s.m_pos);
|
||||
s.m_pos = len;
|
||||
}
|
||||
|
||||
wrapper->writeBuf(buf, s.m_pos);
|
||||
}
|
||||
};
|
||||
|
||||
void put_rawip(const raw_ip& value, Stream* wrapper);
|
||||
|
||||
template<> struct log::Stream::Entry<raw_ip>
|
||||
|
|
|
@ -866,11 +866,16 @@ void P2PServer::show_peers()
|
|||
{
|
||||
MutexLock lock(m_clientsListLock);
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
for (P2PClient* client = static_cast<P2PClient*>(m_connectedClientsList->m_next); client != m_connectedClientsList; client = static_cast<P2PClient*>(client->m_next)) {
|
||||
if (client->m_listenPort >= 0) {
|
||||
LOGINFO(0, (client->m_isIncoming ? "I " : "O ") << client->m_pingTime << " ms\t" << static_cast<char*>(client->m_addrString));
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
||||
LOGINFO(0, "Total: " << n << " peers");
|
||||
}
|
||||
|
||||
void P2PServer::on_timer()
|
||||
|
|
|
@ -447,13 +447,23 @@ void StratumServer::show_workers()
|
|||
|
||||
MutexLock lock(m_clientsListLock);
|
||||
|
||||
for (StratumClient* c = static_cast<StratumClient*>(m_connectedClientsList->m_next); c != m_connectedClientsList; c = static_cast<StratumClient*>(c->m_next)) {
|
||||
LOGINFO(0, static_cast<char*>(c->m_addrString)
|
||||
<< '\t' << (c->m_rpcId ? " " : "*") << log::Duration(cur_time - c->m_connectedTime)
|
||||
<< '\t' << c->m_customDiff
|
||||
<< '\t' << c->m_customUser
|
||||
);
|
||||
int addr_len = 0;
|
||||
for (const StratumClient* c = static_cast<StratumClient*>(m_connectedClientsList->m_next); c != m_connectedClientsList; c = static_cast<StratumClient*>(c->m_next)) {
|
||||
addr_len = std::max(addr_len, static_cast<int>(strlen(c->m_addrString)));
|
||||
}
|
||||
|
||||
size_t n = 0;
|
||||
|
||||
for (const StratumClient* c = static_cast<StratumClient*>(m_connectedClientsList->m_next); c != m_connectedClientsList; c = static_cast<StratumClient*>(c->m_next)) {
|
||||
LOGINFO(0, log::pad_right(static_cast<const char*>(c->m_addrString), addr_len + 8)
|
||||
<< log::pad_right(log::Duration(cur_time - c->m_connectedTime), 20)
|
||||
<< log::pad_right(c->m_customDiff, 20)
|
||||
<< (c->m_rpcId ? c->m_customUser.data() : "not logged in")
|
||||
);
|
||||
++n;
|
||||
}
|
||||
|
||||
LOGINFO(0, "Total: " << n << " workers");
|
||||
}
|
||||
|
||||
void StratumServer::reset_share_counters()
|
||||
|
|
Loading…
Reference in a new issue