From 039fd3daefebaf973df69086c8726c05af48f1ce Mon Sep 17 00:00:00 2001 From: Abhay Deshpande Date: Sat, 20 Jul 2024 01:50:35 -0700 Subject: [PATCH] Fix some logging bugs and improve log levels (#333) --- src/Rover.cpp | 10 ++++++---- src/network/websocket/WebSocketServer.cpp | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Rover.cpp b/src/Rover.cpp index 2ce8d2e2..3961737a 100644 --- a/src/Rover.cpp +++ b/src/Rover.cpp @@ -63,15 +63,17 @@ void parseCommandLine(int argc, char** argv) { {"LOG_ERROR", loguru::Verbosity_ERROR}, {"LOG_WARN", loguru::Verbosity_WARNING}, {"LOG_INFO", loguru::Verbosity_INFO}, - {"LOG_DEBUG", 2}, - {"LOG_TRACE", 1}, + {"LOG_VERBOSE", 1}, + {"LOG_TRACE", 2}, + {"LOG_DEBUG", 3}, }; if (allowed.find(value) != allowed.end()) { loguru::g_stderr_verbosity = allowed[value]; + return value; + } else { + throw std::runtime_error("Invalid log level " + value); } - - throw std::runtime_error("Invalid log level " + value); }); program.add_argument("-nc", "--no-colors") diff --git a/src/network/websocket/WebSocketServer.cpp b/src/network/websocket/WebSocketServer.cpp index 139901cf..a3f20280 100644 --- a/src/network/websocket/WebSocketServer.cpp +++ b/src/network/websocket/WebSocketServer.cpp @@ -159,7 +159,7 @@ void SingleClientWSServer::onOpen(connection_hdl hdl) { ProtocolData& pd = this->getProtocol(path).value(); std::lock_guard lock(pd.mutex); if (pd.client.has_value()) { - LOG_F(2, "Ping!"); + LOG_F(3, "Ping!"); server.ping(pd.client.value(), path); } }); @@ -206,7 +206,7 @@ void SingleClientWSServer::onMessage(connection_hdl hdl, message_t message) { // No need to lock this pd because we only access the protocol, which is constant ProtocolData& pd = protocolDataOpt.value(); std::string jsonStr = message->get_payload(); - LOG_F(1, "Message on %s: %s", path.c_str(), jsonStr.c_str()); + LOG_F(2, "Message on %s: %s", path.c_str(), jsonStr.c_str()); json obj = json::parse(jsonStr); pd.protocol->processMessage(obj); } else { @@ -215,7 +215,7 @@ void SingleClientWSServer::onMessage(connection_hdl hdl, message_t message) { } void SingleClientWSServer::onPong(connection_hdl hdl, const std::string& payload) { - LOG_F(2, "Pong from %s", payload.c_str()); + LOG_F(3, "Pong from %s", payload.c_str()); auto conn = server.get_con_from_hdl(hdl); auto protocolDataOpt = this->getProtocol(payload);