diff --git a/ClientContext.cpp b/ClientContext.cpp index 902667d..4a30351 100644 --- a/ClientContext.cpp +++ b/ClientContext.cpp @@ -3,7 +3,7 @@ #include "KeyboardReader.h" // for KeyboardReader #include // for function -#include +#include #include ClientContext::ClientContext(core::socket::stream::SocketConnection* socketConnection) @@ -37,7 +37,10 @@ std::size_t ClientContext::onReceivedFromPeer() { std::size_t numBytesRead = readFromPeer(buffer, 1024); - VLOG(0) << "Buffer: " << std::string(buffer, numBytesRead); + auto log = snode::semantic::appLog(); + if (log.enabled(logger::LogLevel::Trace)) { + log.trace() << "Buffer: " << std::string(buffer, numBytesRead); + } return numBytesRead; } diff --git a/client.cpp b/client.cpp index 3d264c2..6a17567 100644 --- a/client.cpp +++ b/client.cpp @@ -1,5 +1,5 @@ #include "ClientContext.h" // IWYU pragma: keep -#include "log/Logger.h" +#include #include #include @@ -13,20 +13,21 @@ int main(int argc, char* argv[]) { Client client( [](SocketConnection* socketConnection) -> void { - VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnection* socketConnection) -> void { - VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnection* socketConnection) -> void { - VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); }); client.connect("/tmp/testsocket", [](const Client::SocketAddress& socketAddress, int errnum) -> void { if (errnum == 0) { - VLOG(0) << "Client connected to " << socketAddress.toString(); + snode::semantic::appLog().info() << "Client connected to " << socketAddress.toString(); } else { - VLOG(0) << "Error: Client trying to connect to " << socketAddress.toString() << " : errno = " << errnum; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) + << "Client failed to connect to " << socketAddress.toString(); } }); @@ -35,13 +36,13 @@ int main(int argc, char* argv[]) { ClientTLS clienttls( [](SocketConnectionTLS* socketConnection) -> void { - VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnectionTLS* socketConnection) -> void { - VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnectionTLS* socketConnection) -> void { - VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); }); clienttls.getConfig() @@ -52,11 +53,12 @@ int main(int argc, char* argv[]) { clienttls.connect("localhost", 8082, [](const ClientTLS::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) + << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c connecting to " << socketAddress.toString(); + snode::semantic::appLog().info() << "snode.c connecting to " << socketAddress.toString(); } }); diff --git a/server.cpp b/server.cpp index cf220c0..347c996 100644 --- a/server.cpp +++ b/server.cpp @@ -1,5 +1,5 @@ #include "ServerContext.h" // IWYU pragma: keep -#include "log/Logger.h" +#include #include #include @@ -15,22 +15,23 @@ int main(int argc, char* argv[]) { Server server( [](SocketConnection* socketConnection) -> void { - VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnection* socketConnection) -> void { - VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnection* socketConnection) -> void { - VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); }); server.listen(8080, 5, [](const Server::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) + << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString(); } }); @@ -39,13 +40,13 @@ int main(int argc, char* argv[]) { ServerTLS servertls( [](SocketConnectionTLS* socketConnection) -> void { - VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnectionTLS* socketConnection) -> void { - VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnectionTLS* socketConnection) -> void { - VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); }); servertls.getConfig() @@ -56,11 +57,12 @@ int main(int argc, char* argv[]) { servertls.listen(8082, 5, [](const ServerTLS::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) + << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString(); } }); @@ -69,22 +71,26 @@ int main(int argc, char* argv[]) { Server6 server6( [](SocketConnection6* socketConnection) -> void { - VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnection6* socketConnection) -> void { - VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnection6* socketConnection) -> void { - VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); }); server6.listen(8081, 5, [](const Server6::SocketAddress& socketAddress, core::socket::State errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError( + snode::semantic::appLog(), logger::LogLevel::Error, static_cast(errnum)) + << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError( + snode::semantic::appLog(), logger::LogLevel::Error, static_cast(errnum)) + << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString(); } }); @@ -93,22 +99,26 @@ int main(int argc, char* argv[]) { ServerUn serverUn( [](SocketConnectionUn* socketConnection) -> void { - VLOG(0) << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnect from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnectionUn* socketConnection) -> void { - VLOG(0) << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnConnected from: " << socketConnection->getRemoteAddress().toString(); }, [](SocketConnectionUn* socketConnection) -> void { - VLOG(0) << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << "OnDisconnect from: " << socketConnection->getRemoteAddress().toString(); }); serverUn.listen("/tmp/testsocket", 5, [](const ServerUn::SocketAddress& socketAddress, core::socket::State errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError( + snode::semantic::appLog(), logger::LogLevel::Error, static_cast(errnum)) + << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError( + snode::semantic::appLog(), logger::LogLevel::Error, static_cast(errnum)) + << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().info() << "snode.c listening on " << socketAddress.toString(); } });