mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Enable log macros to work with no args (#4475)
This is enabled by the C++20 __VA_OPT__ feature.
Uses of "{}" format string were updated.
Some warning suppressions were required for older clang versions.
Also improve codegen of wpi::Logger::Log(), frc::ReportError(), and frc::MakeError();
these generate better and less redundant code if they use fmt::string_view for the
format string instead of templating on it.
This commit is contained in:
@@ -6,15 +6,23 @@
|
||||
|
||||
#include <wpi/Logger.h>
|
||||
|
||||
#define LOG(level, format, ...) WPI_LOG(m_logger, level, format, __VA_ARGS__)
|
||||
#define LOG(level, format, ...) \
|
||||
WPI_LOG(m_logger, level, format __VA_OPT__(, ) __VA_ARGS__)
|
||||
|
||||
#undef ERROR
|
||||
#define ERROR(format, ...) WPI_ERROR(m_logger, format, __VA_ARGS__)
|
||||
#define WARNING(format, ...) WPI_WARNING(m_logger, format, __VA_ARGS__)
|
||||
#define INFO(format, ...) WPI_INFO(m_logger, format, __VA_ARGS__)
|
||||
#define ERROR(format, ...) \
|
||||
WPI_ERROR(m_logger, format __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define WARNING(format, ...) \
|
||||
WPI_WARNING(m_logger, format __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define INFO(format, ...) WPI_INFO(m_logger, format __VA_OPT__(, ) __VA_ARGS__)
|
||||
|
||||
#define DEBUG0(format, ...) WPI_DEBUG(m_logger, format, __VA_ARGS__)
|
||||
#define DEBUG1(format, ...) WPI_DEBUG1(m_logger, format, __VA_ARGS__)
|
||||
#define DEBUG2(format, ...) WPI_DEBUG2(m_logger, format, __VA_ARGS__)
|
||||
#define DEBUG3(format, ...) WPI_DEBUG3(m_logger, format, __VA_ARGS__)
|
||||
#define DEBUG4(format, ...) WPI_DEBUG4(m_logger, format, __VA_ARGS__)
|
||||
#define DEBUG0(format, ...) \
|
||||
WPI_DEBUG(m_logger, format __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define DEBUG1(format, ...) \
|
||||
WPI_DEBUG1(m_logger, format __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define DEBUG2(format, ...) \
|
||||
WPI_DEBUG2(m_logger, format __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define DEBUG3(format, ...) \
|
||||
WPI_DEBUG3(m_logger, format __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define DEBUG4(format, ...) \
|
||||
WPI_DEBUG4(m_logger, format __VA_OPT__(, ) __VA_ARGS__)
|
||||
|
||||
@@ -131,7 +131,7 @@ NCImpl::NCImpl(int inst, std::string_view id, net::ILocalStorage& localStorage,
|
||||
m_loop{*m_loopRunner.GetLoop()} {
|
||||
m_localMsgs.reserve(net::NetworkLoopQueue::kInitialQueueSize);
|
||||
|
||||
INFO("{}", "starting network client");
|
||||
INFO("starting network client");
|
||||
}
|
||||
|
||||
void NCImpl::SetServers(
|
||||
@@ -285,13 +285,13 @@ void NCImpl3::TcpConnected(uv::Tcp& tcp) {
|
||||
}
|
||||
});
|
||||
tcp.end.connect([this, &tcp] {
|
||||
DEBUG3("{}", "NT3 TCP read ended");
|
||||
DEBUG3("NT3 TCP read ended");
|
||||
if (!tcp.IsLoopClosing()) {
|
||||
Disconnect("remote end closed connection");
|
||||
}
|
||||
});
|
||||
tcp.closed.connect([this, &tcp] {
|
||||
DEBUG3("{}", "NT3 TCP connection closed");
|
||||
DEBUG3("NT3 TCP connection closed");
|
||||
if (!tcp.IsLoopClosing()) {
|
||||
Disconnect(m_wire->GetDisconnectReason());
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ void NSImpl::LoadPersistent() {
|
||||
is.readinto(m_persistentData, size);
|
||||
DEBUG4("read data: {}", m_persistentData);
|
||||
if (is.has_error()) {
|
||||
WARNING("{}", "error reading persistent file");
|
||||
WARNING("error reading persistent file");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -453,7 +453,7 @@ void NSImpl::Init() {
|
||||
if (uv::AddrToName(tcp->GetPeer(), &peerAddr, &peerPort) == 0) {
|
||||
INFO("Got a NT3 connection from {} port {}", peerAddr, peerPort);
|
||||
} else {
|
||||
INFO("{}", "Got a NT3 connection from unknown");
|
||||
INFO("Got a NT3 connection from unknown");
|
||||
}
|
||||
auto conn = std::make_shared<ServerConnection3>(tcp, *this, peerAddr,
|
||||
peerPort, m_logger);
|
||||
@@ -485,7 +485,7 @@ void NSImpl::Init() {
|
||||
if (uv::AddrToName(tcp->GetPeer(), &peerAddr, &peerPort) == 0) {
|
||||
INFO("Got a NT4 connection from {} port {}", peerAddr, peerPort);
|
||||
} else {
|
||||
INFO("{}", "Got a NT4 connection from unknown");
|
||||
INFO("Got a NT4 connection from unknown");
|
||||
}
|
||||
auto conn = std::make_shared<ServerConnection4>(tcp, *this, peerAddr,
|
||||
peerPort, m_logger);
|
||||
@@ -496,7 +496,7 @@ void NSImpl::Init() {
|
||||
}
|
||||
|
||||
if (m_initDone) {
|
||||
DEBUG4("{}", "NetworkServer initDone()");
|
||||
DEBUG4("NetworkServer initDone()");
|
||||
m_initDone();
|
||||
m_initDone = nullptr;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ void CImpl::ProcessIncomingBinary(std::span<const uint8_t> data) {
|
||||
}
|
||||
|
||||
void CImpl::HandleLocal(std::vector<ClientMessage>&& msgs) {
|
||||
DEBUG4("{}", "HandleLocal()");
|
||||
DEBUG4("HandleLocal()");
|
||||
for (auto&& elem : msgs) {
|
||||
// common case is value
|
||||
if (auto msg = std::get_if<ClientValueMsg>(&elem.contents)) {
|
||||
|
||||
@@ -45,7 +45,7 @@ void NetworkLoopQueue::SetValue(NT_Publisher pubHandle, const Value& value) {
|
||||
m_size += sizeof(ClientMessage);
|
||||
if (m_size > kMaxSize) {
|
||||
if (!m_sizeErrored) {
|
||||
WPI_ERROR(m_logger, "{}", "NT: dropping value set due to memory limits");
|
||||
WPI_ERROR(m_logger, "NT: dropping value set due to memory limits");
|
||||
m_sizeErrored = true;
|
||||
}
|
||||
return; // avoid potential out of memory
|
||||
|
||||
@@ -758,7 +758,7 @@ void ClientDataLocal::SendPropertiesUpdate(TopicData* topic,
|
||||
}
|
||||
|
||||
void ClientDataLocal::HandleLocal(std::span<const ClientMessage> msgs) {
|
||||
DEBUG4("{}", "HandleLocal()");
|
||||
DEBUG4("HandleLocal()");
|
||||
// just map as a normal client into client=0 calls
|
||||
for (const auto& elem : msgs) { // NOLINT
|
||||
// common case is value, so check that first
|
||||
@@ -2145,7 +2145,7 @@ void SImpl::UpdateMetaClients(const std::vector<ConnectionInfo>& conns) {
|
||||
if (mpack_writer_destroy(&w) == mpack_ok) {
|
||||
SetValue(nullptr, m_metaClients, Value::MakeRaw(std::move(w.bytes)));
|
||||
} else {
|
||||
DEBUG4("{}", "failed to encode $clients");
|
||||
DEBUG4("failed to encode $clients");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ static void WireDecodeTextImpl(std::string_view in, T& out,
|
||||
}
|
||||
|
||||
if (!j.is_array()) {
|
||||
WPI_WARNING(logger, "{}", "expected JSON array at top level");
|
||||
WPI_WARNING(logger, "expected JSON array at top level");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ void CImpl::SendPeriodic(uint64_t curTimeMs, bool initial) {
|
||||
if (!CheckNetworkReady()) {
|
||||
return;
|
||||
}
|
||||
DEBUG4("{}", "Sending keep alive");
|
||||
DEBUG4("Sending keep alive");
|
||||
WireEncodeKeepAlive(out.stream());
|
||||
// drift isn't critical here, so just go from current time
|
||||
m_nextKeepAliveTimeMs = curTimeMs + kKeepAliveIntervalMs;
|
||||
@@ -274,7 +274,7 @@ void CImpl::SendPeriodic(uint64_t curTimeMs, bool initial) {
|
||||
}
|
||||
|
||||
if (initial) {
|
||||
DEBUG4("{}", "Sending ClientHelloDone");
|
||||
DEBUG4("Sending ClientHelloDone");
|
||||
WireEncodeClientHelloDone(out.stream());
|
||||
}
|
||||
|
||||
@@ -403,7 +403,7 @@ void CImpl::SetValue(NT_Publisher pubHandle, const Value& value) {
|
||||
}
|
||||
|
||||
void CImpl::KeepAlive() {
|
||||
DEBUG4("{}", "KeepAlive()");
|
||||
DEBUG4("KeepAlive()");
|
||||
if (m_state != kStateRunning && m_state != kStateInitialAssignments) {
|
||||
m_decoder.SetError("received unexpected KeepAlive message");
|
||||
return;
|
||||
@@ -412,7 +412,7 @@ void CImpl::KeepAlive() {
|
||||
}
|
||||
|
||||
void CImpl::ServerHelloDone() {
|
||||
DEBUG4("{}", "ServerHelloDone()");
|
||||
DEBUG4("ServerHelloDone()");
|
||||
if (m_state != kStateInitialAssignments) {
|
||||
m_decoder.SetError("received unexpected ServerHelloDone message");
|
||||
return;
|
||||
@@ -426,7 +426,7 @@ void CImpl::ServerHelloDone() {
|
||||
}
|
||||
|
||||
void CImpl::ClientHelloDone() {
|
||||
DEBUG4("{}", "ClientHelloDone()");
|
||||
DEBUG4("ClientHelloDone()");
|
||||
m_decoder.SetError("received unexpected ClientHelloDone message");
|
||||
}
|
||||
|
||||
@@ -572,7 +572,7 @@ void CImpl::EntryDelete(unsigned int id) {
|
||||
}
|
||||
|
||||
void CImpl::ClearEntries() {
|
||||
DEBUG4("{}", "ClearEntries()");
|
||||
DEBUG4("ClearEntries()");
|
||||
if (m_state != kStateRunning) {
|
||||
m_decoder.SetError("received ClearEntries message before ServerHelloDone");
|
||||
return;
|
||||
@@ -609,7 +609,7 @@ ClientImpl3::ClientImpl3(uint64_t curTimeMs, int inst, WireConnection3& wire,
|
||||
std::move(setPeriodic))} {}
|
||||
|
||||
ClientImpl3::~ClientImpl3() {
|
||||
WPI_DEBUG4(m_impl->m_logger, "{}", "NT3 ClientImpl destroyed");
|
||||
WPI_DEBUG4(m_impl->m_logger, "NT3 ClientImpl destroyed");
|
||||
}
|
||||
|
||||
void ClientImpl3::Start(std::string_view selfId,
|
||||
|
||||
Reference in New Issue
Block a user