diff --git a/README.md b/README.md index 08c0d8d53c..eb8be68df9 100644 --- a/README.md +++ b/README.md @@ -297,7 +297,7 @@ Sending data to the client is done using the method `sendToPeer()`, which is als #include #include #include -#include +#include // #include #include @@ -308,15 +308,15 @@ public: private: void onConnected() override { // Called in case a connection has been established successfully. - VLOG(1) << "Echo connected to " << getSocketConnection()->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "Echo connected to " << getSocketConnection()->getRemoteAddress().toString(); } void onDisconnected() override { // Called in case the connection has been closed. - VLOG(1) << "Echo disconnected from " << getSocketConnection()->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "Echo disconnected from " << getSocketConnection()->getRemoteAddress().toString(); } bool onSignal(int signum) override { // Called in case a signal has been received - VLOG(1) << "Echo disconnected due to signal=" << signum; + snode::semantic::appLog().trace() << "Echo disconnected due to signal=" << signum; return true; // Close the connection } @@ -331,7 +331,7 @@ private: // onReceivedFromPeer will be called again. // No error can occure here. if (chunkLen > 0) { - VLOG(1) << "Data to reflect: " << std::string(chunk, chunkLen); + snode::semantic::appLog().trace() << "Data to reflect: " << std::string(chunk, chunkLen); sendToPeer(chunk, chunkLen); // Reflect the received data back to the client. // Out of memory is the only error which can occure here. } @@ -351,7 +351,7 @@ And like in the `EchoServerContext`, `readFromPeer()` and `sendToPeer()` is used #include #include #include -#include +#include // #include #include @@ -362,18 +362,18 @@ public: private: void onConnected() override { // Called in case a connection has been established successfully. - VLOG(1) << "Echo connected to " << getSocketConnection()->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "Echo connected to " << getSocketConnection()->getRemoteAddress().toString(); - VLOG(1) << "Initiating data exchange"; + snode::semantic::appLog().trace() << "Initiating data exchange"; sendToPeer("Hello peer! It's nice talking to you\n"); // Initiate the ping-pong data exchange. } void onDisconnected() override { // Called in case the connection has been closed. - VLOG(1) << "Echo disconnected from " << getSocketConnection()->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "Echo disconnected from " << getSocketConnection()->getRemoteAddress().toString(); } bool onSignal(int signum) override { // Called in case a signal has been received - VLOG(1) << "Echo disconnected due to signal=" << signum; + snode::semantic::appLog().trace() << "Echo disconnected due to signal=" << signum; return true; // Close the connection } @@ -388,7 +388,7 @@ private: // onReceivedFromPeer will be called again. // No error can occure here. if (chunkLen > 0) { - VLOG(1) << "Data to reflect: " << std::string(chunk, chunkLen); + snode::semantic::appLog().trace() << "Data to reflect: " << std::string(chunk, chunkLen); sendToPeer(chunk, chunkLen); // Reflect the received data back to the server. // Out of memory is the only error which can occure here. } @@ -449,16 +449,16 @@ int main(int argc, char* argv[]) { echoServer.listen(8001, 5, [](const SocketAddress& socketAddress, const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "EchoServer: connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "EchoServer: connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "EchoServer: disabled"; + snode::semantic::appLog().trace() << "EchoServer: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "EchoServer: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << "EchoServer: " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << "EchoServer: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << "EchoServer: " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -502,16 +502,16 @@ int main(int argc, char* argv[]) { echoClient.connect("localhost", 8001, [](const SocketAddress& socketAddress, const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "EchoClient: connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "EchoClient: connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "EchoClient: disabled"; + snode::semantic::appLog().trace() << "EchoClient: disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << "EchoClient: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << "EchoClient: " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << "EchoClient: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << "EchoClient: " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -1149,13 +1149,13 @@ using SocketAddress = EchoServer::SocketAddress; using SocketConnection = EchoServer::SocketConnection; EchoServer echoServer([] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer estableshed"; + snode::semantic::appLog().trace() << "Connection to peer estableshed"; }, [] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer ready to be used"; + snode::semantic::appLog().trace() << "Connection to peer ready to be used"; }, [] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer closed"; + snode::semantic::appLog().trace() << "Connection to peer closed"; }); echoServer.listen(...); @@ -1169,13 +1169,13 @@ using SocketAddress = EchoClient::SocketAddress; using SocketConnection = EchoClient::SocketConnection; EchoClient echoClient([] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer estableshed"; + snode::semantic::appLog().trace() << "Connection to peer estableshed"; }, [] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer ready to be used"; + snode::semantic::appLog().trace() << "Connection to peer ready to be used"; }, [] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer closed"; + snode::semantic::appLog().trace() << "Connection to peer closed"; }); echoClient.connect(...); @@ -1199,15 +1199,15 @@ using SocketConnection = EchoServer::SocketConnection; EchoServer echoServer; echoServer.setOnConnect([] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer established"; + snode::semantic::appLog().trace() << "Connection to peer established"; }); echoServer.setOnConnected([] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer ready to be used"; + snode::semantic::appLog().trace() << "Connection to peer ready to be used"; }); echoServer.setOnDisconnected([] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer closed"; + snode::semantic::appLog().trace() << "Connection to peer closed"; }); echoServer.listen(...); @@ -1223,15 +1223,15 @@ using SocketConnection = EchoClient::SocketConnection; EchoClient echoClient; echoClient.setOnConnect([] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer established"; + snode::semantic::appLog().trace() << "Connection to peer established"; }); echoClient.setOnConnected([] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer ready to be used"; + snode::semantic::appLog().trace() << "Connection to peer ready to be used"; }); echoClient.setOnDisconnected([] (SocketConnection* socketConnection) -> void { - VLOG(1) << "Connection to peer closed"; + snode::semantic::appLog().trace() << "Connection to peer closed"; }); echoClient.connect(...); @@ -2436,16 +2436,16 @@ In that case the Main-Application would look like const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "EchoServerIn: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "EchoServerIn: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "EchoServerIn: disabled"; + snode::semantic::appLog().trace() << "EchoServerIn: disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << "EchoServerIn: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << "EchoServerIn: " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << "EchoServerIn: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << "EchoServerIn: " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -2459,16 +2459,16 @@ In that case the Main-Application would look like const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "EchoServerUn: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "EchoServerUn: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "EchoServerUn: disabled"; + snode::semantic::appLog().trace() << "EchoServerUn: disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << "EchoServerUn: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << "EchoServerUn: " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << "EchoServerUn: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << "EchoServerUn: " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -2487,16 +2487,16 @@ In that case the Main-Application would look like const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "EchoServerRc: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "EchoServerRc: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "EchoServerRc: disabled"; + snode::semantic::appLog().trace() << "EchoServerRc: disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << "EchoServerRc: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << "EchoServerRc: " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << "EchoServerRc: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << "EchoServerRc: " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -2522,16 +2522,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "EchoClientIn: connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "EchoClientIn: connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "EchoClientIn: disabled"; + snode::semantic::appLog().trace() << "EchoClientIn: disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << "EchoClientIn: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << "EchoClientIn: " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << "EchoClientIn: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << "EchoClientIn: " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -2546,16 +2546,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "EchoClientUn: connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "EchoClientUn: connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "EchoClientUn: disabled"; + snode::semantic::appLog().trace() << "EchoClientUn: disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << "EchoClientUn: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << "EchoClientUn: " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << "EchoClientUn: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << "EchoClientUn: " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -2576,16 +2576,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "EchoClientRc: connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "EchoClientRc: connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "EchoClientRc: disabled"; + snode::semantic::appLog().trace() << "EchoClientRc: disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << "EchoClientRc: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << "EchoClientRc: " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << "EchoClientRc: " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << "EchoClientRc: " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -2636,7 +2636,7 @@ The use of X.509 certificates for encrypted communication is demonstrated also. #include #include #include -#include +#include #include int main(int argc, char* argv[]) { @@ -2656,23 +2656,23 @@ int main(int argc, char* argv[]) { configLegacyApp.required(legacyHtmlRoot); legacyApp.setOnConnected([legacyApp, legacyHtmlRoot](SocketConnection* socketConnection) -> void { // onConnect - LOG(INFO) << "OnConnected " << legacyApp.getConfig().getInstanceName(); + snode::semantic::appLog().info() << "OnConnected " << legacyApp.getConfig().getInstanceName(); legacyApp.use(express::middleware::StaticMiddleware(legacyHtmlRoot->as())); }); legacyApp.listen(8080, [](const SocketAddressRc& socketAddress, const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "LegacyWebApp: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "LegacyWebApp: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "LegacyWebApp: disabled"; + snode::semantic::appLog().trace() << "LegacyWebApp: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "LegacyWebApp: non critical error occurred"; + snode::semantic::appLog().trace() << "LegacyWebApp: non critical error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "LegacyWebApp: critical error occurred"; + snode::semantic::appLog().trace() << "LegacyWebApp: critical error occurred"; break; } }); @@ -2689,7 +2689,7 @@ int main(int argc, char* argv[]) { configTlsApp.required(tlsHtmlRoot); tlsApp.setOnConnected([tlsApp, tlsHtmlRoot](SocketConnection* socketConnection) -> void { // onConnect - LOG(INFO) << "OnConnected " << tlsApp.getConfig().getInstanceName(); + snode::semantic::appLog().info() << "OnConnected " << tlsApp.getConfig().getInstanceName(); tlsApp.use(express::middleware::StaticMiddleware(tlsHtmlRoot->as())); }); @@ -2700,16 +2700,16 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const SocketAddressRc& socketAddress, const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "TLSWebApp: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "TLSWebApp: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "TLSWebApp: disabled"; + snode::semantic::appLog().trace() << "TLSWebApp: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "TLSWebApp: non critical error occurred"; + snode::semantic::appLog().trace() << "TLSWebApp: non critical error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "TLSWebApp: critical error occurred"; + snode::semantic::appLog().trace() << "TLSWebApp: critical error occurred"; break; } }); @@ -2725,7 +2725,7 @@ The high-level web API provides the methods `get()`, `post()`, `put()`, etc like ```cpp #include #include -#include +#include int main(int argc, char* argv[]) { express::WebApp::init(argc, argv); @@ -2786,16 +2786,16 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const SocketAddressRc& socketAddress, const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "LegacyWebApp: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "LegacyWebApp: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "LegacyWebApp: disabled"; + snode::semantic::appLog().trace() << "LegacyWebApp: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "LegacyWebApp: non critical error occurred"; + snode::semantic::appLog().trace() << "LegacyWebApp: non critical error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "LegacyWebApp: critical error occurred"; + snode::semantic::appLog().trace() << "LegacyWebApp: critical error occurred"; break; } }); @@ -2814,16 +2814,16 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const SocketAddressRc& socketAddress, const core::socket::State& state) -> void { switch (state) { case core::socket::State::OK: - VLOG(1) << "TLSWebApp: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "TLSWebApp: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "TLSWebApp: disabled"; + snode::semantic::appLog().trace() << "TLSWebApp: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "TLSWebApp: non critical error occurred"; + snode::semantic::appLog().trace() << "TLSWebApp: non critical error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "TLSWebApp: critical error occurred"; + snode::semantic::appLog().trace() << "TLSWebApp: critical error occurred"; break; } }); diff --git a/src/SemanticLog.h b/src/SemanticLog.h new file mode 100644 index 0000000000..ff8d0ca49b --- /dev/null +++ b/src/SemanticLog.h @@ -0,0 +1,85 @@ +#ifndef SNODEC_SEMANTICLOG_H +#define SNODEC_SEMANTICLOG_H + +#include "log/Logger.h" + +#include + +namespace logger { + + enum class LogLevel { + Trace, + Debug, + Info, + Warning, + Error, + Critical, + }; + +} // namespace logger + +namespace snode::semantic { + + namespace detail { + + inline logger::Level backendLevel(logger::LogLevel level) { + switch (level) { + case logger::LogLevel::Trace: + return logger::Level::TRACE; + case logger::LogLevel::Debug: + return logger::Level::DEBUG; + case logger::LogLevel::Info: + return logger::Level::INFO; + case logger::LogLevel::Warning: + return logger::Level::WARNING; + case logger::LogLevel::Error: + return logger::Level::ERROR; + case logger::LogLevel::Critical: + return logger::Level::FATAL; + } + + return logger::Level::INFO; + } + + } // namespace detail + + class AppLog { + public: + logger::LogMessage trace() const { + return logger::LogMessage(logger::Level::TRACE); + } + + logger::LogMessage debug() const { + return logger::LogMessage(logger::Level::DEBUG); + } + + logger::LogMessage info() const { + return logger::LogMessage(logger::Level::INFO); + } + + logger::LogMessage warn() const { + return logger::LogMessage(logger::Level::WARNING); + } + + logger::LogMessage error() const { + return logger::LogMessage(logger::Level::ERROR); + } + + logger::LogMessage critical() const { + return logger::LogMessage(logger::Level::FATAL); + } + }; + + inline const AppLog& appLog() { + static const AppLog log; + return log; + } + + inline logger::LogMessage sysError(const AppLog&, logger::LogLevel level, int errnum) { + errno = errnum; + return logger::LogMessage(detail::backendLevel(level), -1, true); + } + +} // namespace snode::semantic + +#endif // SNODEC_SEMANTICLOG_H diff --git a/src/apps/configtest.cpp b/src/apps/configtest.cpp index 41d02cf437..af79cab68d 100644 --- a/src/apps/configtest.cpp +++ b/src/apps/configtest.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -82,7 +83,7 @@ int main(int argc, char* argv[]) { CLI::Option* filenameOpt = subApp->add_option("-f", filename, "A Filename"); // filenameOpt->default_val("Filenameeeeee"); - VLOG(1) << "Filename: " << filename; + snode::semantic::appLog().trace() << "Filename: " << filename; // app.needs(subApp); // subApp->needs(filenameOpt); diff --git a/src/apps/database/testmariadb.cpp b/src/apps/database/testmariadb.cpp index 566e6ff939..b9fe5d87cf 100644 --- a/src/apps/database/testmariadb.cpp +++ b/src/apps/database/testmariadb.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -112,11 +113,11 @@ int main(int argc, char* argv[]) { database::mariadb::MariaDBClient db1(details, [](const database::mariadb::MariaDBState& state) { if (state.error != 0) { - VLOG(0) << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; + snode::semantic::appLog().trace() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; } else if (state.connected) { - VLOG(0) << "MySQL connected"; + snode::semantic::appLog().trace() << "MySQL connected"; } else { - VLOG(0) << "MySQL disconnected"; + snode::semantic::appLog().trace() << "MySQL disconnected"; } }); @@ -125,68 +126,68 @@ int main(int argc, char* argv[]) { db1.exec( "DELETE FROM `snodec`", [&db1](void) -> void { - VLOG(0) << "********** OnQuery 0;"; + snode::semantic::appLog().trace() << "********** OnQuery 0;"; db1.affectedRows( [](my_ulonglong affectedRows) -> void { - VLOG(0) << "********** AffectedRows 1: " << affectedRows; + snode::semantic::appLog().trace() << "********** AffectedRows 1: " << affectedRows; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 1: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 1: " << errorString << " : " << errorNumber; }); }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "********** Error 0: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "********** Error 0: " << errorString << " : " << errorNumber; }) .exec( "INSERT INTO `snodec`(`username`, `password`) VALUES ('Annett','Hallo')", [&db1](void) -> void { - VLOG(0) << "********** OnQuery 1: "; + snode::semantic::appLog().trace() << "********** OnQuery 1: "; db1.affectedRows( [](my_ulonglong affectedRows) -> void { - VLOG(0) << "********** AffectedRows 2: " << affectedRows; + snode::semantic::appLog().trace() << "********** AffectedRows 2: " << affectedRows; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "********** Error 2: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "********** Error 2: " << errorString << " : " << errorNumber; }); }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "********** Error 1: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "********** Error 1: " << errorString << " : " << errorNumber; }) .query( "SELECT * FROM snodec", [&r](const MYSQL_ROW row) -> void { if (row != nullptr) { - VLOG(0) << "********** Row Result 2: " << row[0] << " : " << row[1]; + snode::semantic::appLog().trace() << "********** Row Result 2: " << row[0] << " : " << row[1]; r++; } else { - VLOG(0) << "********** Row Result 2: " << r; + snode::semantic::appLog().trace() << "********** Row Result 2: " << r; } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "********** Error 2: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "********** Error 2: " << errorString << " : " << errorNumber; }) .query( "SELECT * FROM snodec", [&r](const MYSQL_ROW row) -> void { if (row != nullptr) { - VLOG(0) << "********** Row Result 2: " << row[0] << " : " << row[1]; + snode::semantic::appLog().trace() << "********** Row Result 2: " << row[0] << " : " << row[1]; r++; } else { - VLOG(0) << "********** Row Result 2: " << r; + snode::semantic::appLog().trace() << "********** Row Result 2: " << r; } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "********** Error 2: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "********** Error 2: " << errorString << " : " << errorNumber; }); database::mariadb::MariaDBClient db2(details, [](const database::mariadb::MariaDBState& state) { if (state.error != 0) { - VLOG(0) << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; + snode::semantic::appLog().trace() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; } else if (state.connected) { - VLOG(0) << "MySQL connected"; + snode::semantic::appLog().trace() << "MySQL connected"; } else { - VLOG(0) << "MySQL disconnected"; + snode::semantic::appLog().trace() << "MySQL disconnected"; } }); @@ -197,49 +198,49 @@ int main(int argc, char* argv[]) { "SELECT * FROM snodec", [](const MYSQL_ROW row) -> void { if (row != nullptr) { - VLOG(0) << "Row Result 3: " << row[0] << " : " << row[1]; + snode::semantic::appLog().trace() << "Row Result 3: " << row[0] << " : " << row[1]; } else { - VLOG(0) << "Row Result 3:"; + snode::semantic::appLog().trace() << "Row Result 3:"; } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 3: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 3: " << errorString << " : " << errorNumber; }); db2.query( "SELECT * FROM snodec", [&db2, &r1, &r2](const MYSQL_ROW row) -> void { if (row != nullptr) { - VLOG(0) << "Row Result 4: " << row[0] << " : " << row[1]; + snode::semantic::appLog().trace() << "Row Result 4: " << row[0] << " : " << row[1]; } else { - VLOG(0) << "Row Result 4:"; + snode::semantic::appLog().trace() << "Row Result 4:"; db2.query( "SELECT * FROM snodec", [&db2, &r1, &r2](const MYSQL_ROW row) -> void { if (row != nullptr) { - VLOG(0) << "Row Result 5: " << row[0] << " : " << row[1]; + snode::semantic::appLog().trace() << "Row Result 5: " << row[0] << " : " << row[1]; } else { // After all results have been fetched - VLOG(0) << "Row Result 5:"; + snode::semantic::appLog().trace() << "Row Result 5:"; core::timer::Timer dbTimer1 = core::timer::Timer::intervalTimer( [&db2, &r1](const std::function& stop) -> void { static int i = 0; - VLOG(0) << "Tick 2: " << i++; + snode::semantic::appLog().trace() << "Tick 2: " << i++; r1 = 0; db2.query( "SELECT * FROM snodec", [&r1](const MYSQL_ROW row) -> void { if (row != nullptr) { - VLOG(0) << "Row Result 6: " << row[0] << " : " << row[1]; + snode::semantic::appLog().trace() << "Row Result 6: " << row[0] << " : " << row[1]; r1++; } else { - VLOG(0) << "Row Result 6: " << r1; + snode::semantic::appLog().trace() << "Row Result 6: " << r1; } }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 6: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 6: " << errorString << " : " << errorNumber; stop(); }); }, @@ -248,146 +249,146 @@ int main(int argc, char* argv[]) { core::timer::Timer dbTimer2 = core::timer::Timer::intervalTimer( [&db2, &r2](const std::function& stop) -> void { static int i = 0; - VLOG(0) << "Tick 0.7: " << i++; + snode::semantic::appLog().trace() << "Tick 0.7: " << i++; r2 = 0; db2.query( "SELECT * FROM snodec", [&db2, &r2](const MYSQL_ROW row) -> void { if (row != nullptr) { - VLOG(0) << "Row Result 7: " << row[0] << " : " << row[1]; + snode::semantic::appLog().trace() << "Row Result 7: " << row[0] << " : " << row[1]; r2++; } else { - VLOG(0) << "Row Result 7: " << r2; + snode::semantic::appLog().trace() << "Row Result 7: " << r2; db2.fieldCount( [](unsigned int fieldCount) -> void { - VLOG(0) << "************ FieldCount ************ = " << fieldCount; + snode::semantic::appLog().trace() << "************ FieldCount ************ = " << fieldCount; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 7: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 7: " << errorString << " : " << errorNumber; }); } }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 7: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 7: " << errorString << " : " << errorNumber; stop(); }) .fieldCount( [](unsigned int fieldCount) -> void { - VLOG(0) << "************ FieldCount ************ = " << fieldCount; + snode::semantic::appLog().trace() << "************ FieldCount ************ = " << fieldCount; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 7: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 7: " << errorString << " : " << errorNumber; }); }, 0.7); } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 5: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 5: " << errorString << " : " << errorNumber; }); } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 4: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 4: " << errorString << " : " << errorNumber; }); core::timer::Timer dbTimer = core::timer::Timer::intervalTimer( [&db2](const std::function& stop) -> void { static int i = 0; - VLOG(0) << "Tick 0.1: " << i++; + snode::semantic::appLog().trace() << "Tick 0.1: " << i++; if (i >= 60000) { - VLOG(0) << "Stop Stop"; + snode::semantic::appLog().trace() << "Stop Stop"; stop(); } int j = i; db2.startTransactions( [](void) -> void { - VLOG(0) << "Transactions activated 10:"; + snode::semantic::appLog().trace() << "Transactions activated 10:"; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 8: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 8: " << errorString << " : " << errorNumber; }) .exec( "INSERT INTO `snodec`(`username`, `password`) VALUES ('Annett','Hallo')", [&db2, j](void) -> void { - VLOG(0) << "Inserted 10: " << j; + snode::semantic::appLog().trace() << "Inserted 10: " << j; db2.affectedRows( [](my_ulonglong affectedRows) -> void { - VLOG(0) << "AffectedRows 11: " << affectedRows; + snode::semantic::appLog().trace() << "AffectedRows 11: " << affectedRows; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 11: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 11: " << errorString << " : " << errorNumber; }); }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 10: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 10: " << errorString << " : " << errorNumber; stop(); }) .rollback( [](void) -> void { - VLOG(0) << "Rollback success 11"; + snode::semantic::appLog().trace() << "Rollback success 11"; }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 12: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 12: " << errorString << " : " << errorNumber; stop(); }) .exec( "INSERT INTO `snodec`(`username`, `password`) VALUES ('Annett','Hallo')", [&db2, j](void) -> void { - VLOG(0) << "Inserted 13: " << j; + snode::semantic::appLog().trace() << "Inserted 13: " << j; db2.affectedRows( [](my_ulonglong affectedRows) -> void { - VLOG(0) << "AffectedRows 14: " << affectedRows; + snode::semantic::appLog().trace() << "AffectedRows 14: " << affectedRows; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 14: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 14: " << errorString << " : " << errorNumber; }); }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 13: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 13: " << errorString << " : " << errorNumber; stop(); }) .commit( [](void) -> void { - VLOG(0) << "Commit success 15"; + snode::semantic::appLog().trace() << "Commit success 15"; }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 15: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 15: " << errorString << " : " << errorNumber; stop(); }) .query( "SELECT COUNT(*) FROM snodec", [&db2, j, stop](const MYSQL_ROW row) -> void { if (row != nullptr) { - VLOG(0) << "Row Result count(*) 16: " << row[0]; + snode::semantic::appLog().trace() << "Row Result count(*) 16: " << row[0]; if (std::atoi(row[0]) != j + 1) { // NOLINT - VLOG(0) << "Wrong number of rows 16: " << std::atoi(row[0]) << " != " << j + 1; // NOLINT + snode::semantic::appLog().trace() << "Wrong number of rows 16: " << std::atoi(row[0]) << " != " << j + 1; // NOLINT // exit(1); } } else { - VLOG(0) << "Row Result count(*) 16: no result:"; + snode::semantic::appLog().trace() << "Row Result count(*) 16: no result:"; db2.fieldCount( [](unsigned int fieldCount) -> void { - VLOG(0) << "************ FieldCount ************ = " << fieldCount; + snode::semantic::appLog().trace() << "************ FieldCount ************ = " << fieldCount; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 7: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 7: " << errorString << " : " << errorNumber; }); } }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 16: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 16: " << errorString << " : " << errorNumber; stop(); }) .endTransactions( [](void) -> void { - VLOG(0) << "Transactions deactivated 17"; + snode::semantic::appLog().trace() << "Transactions deactivated 17"; }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Error 17: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error 17: " << errorString << " : " << errorNumber; stop(); }); }, diff --git a/src/apps/echo/echoclient.cpp b/src/apps/echo/echoclient.cpp index 42e4b71382..aebc33d958 100644 --- a/src/apps/echo/echoclient.cpp +++ b/src/apps/echo/echoclient.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -59,16 +60,16 @@ int main(int argc, char* argv[]) { [instanceName = client.getConfig()->getInstanceName()](const SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -76,16 +77,16 @@ int main(int argc, char* argv[]) { client.connect([](const SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "echoclient: connected to '" << socketAddress.toString() << "'" << "'"; + snode::semantic::appLog().trace() << "echoclient: connected to '" << socketAddress.toString() << "'" << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "echoclient: disabled"; + snode::semantic::appLog().trace() << "echoclient: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "echoclientt: error occurred"; + snode::semantic::appLog().trace() << "echoclientt: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "echoclient: fatal error occurred"; + snode::semantic::appLog().trace() << "echoclient: fatal error occurred"; break; } }); @@ -121,12 +122,12 @@ int main(int argc, char* argv[]) { #endif if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { errno = errnum; - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(1) << "snode.c connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c connecting to " << socketAddress.toString(); } #ifdef NET_TYPE diff --git a/src/apps/echo/echoserver.cpp b/src/apps/echo/echoserver.cpp index ce045eb0f1..4b960b6350 100644 --- a/src/apps/echo/echoserver.cpp +++ b/src/apps/echo/echoserver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -83,16 +84,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -127,9 +128,9 @@ int main(int argc, char* argv[]) { server.listen("/tmp/testme", 5, [](const SocketServer::Socket& socket, int errnum) { // titan #endif if (errnum != 0) { - PLOG(FATAL) << "listen"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Critical, errno) << "listen"; } else { - VLOG(1) << "snode.c listening on " << socket.getBindAddress().toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socket.getBindAddress().toString(); } #ifdef NET_TYPE diff --git a/src/apps/echo/model/EchoSocketContext.cpp b/src/apps/echo/model/EchoSocketContext.cpp index d2480e2912..a3b4d2cc63 100644 --- a/src/apps/echo/model/EchoSocketContext.cpp +++ b/src/apps/echo/model/EchoSocketContext.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -57,7 +58,7 @@ namespace apps::echo::model { } void EchoSocketContext::onConnected() { - VLOG(1) << "Echo connected"; + snode::semantic::appLog().trace() << "Echo connected"; if (role == Role::CLIENT) { sendToPeer("Hello peer! Nice to see you!!!"); @@ -65,7 +66,7 @@ namespace apps::echo::model { } void EchoSocketContext::onDisconnected() { - VLOG(1) << "Echo disconnected"; + snode::semantic::appLog().trace() << "Echo disconnected"; } bool EchoSocketContext::onSignal([[maybe_unused]] int signum) { @@ -78,7 +79,7 @@ namespace apps::echo::model { const std::size_t chunklen = readFromPeer(chunk, 4096); if (chunklen > 0) { - VLOG(1) << "Data to reflect: " << std::string(chunk, chunklen); + snode::semantic::appLog().trace() << "Data to reflect: " << std::string(chunk, chunklen); sendToPeer(chunk, chunklen); } diff --git a/src/apps/echo/model/clients.h b/src/apps/echo/model/clients.h index 70550c7566..bed4322f5e 100644 --- a/src/apps/echo/model/clients.h +++ b/src/apps/echo/model/clients.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -90,10 +91,10 @@ namespace apps::echo::model::tls { EchoSocketClient client("echoclient"); client.setOnConnect([&client](SocketConnection* socketConnection) { // onConnect - VLOG(1) << "OnConnect " << client.getConfig()->getInstanceName(); + snode::semantic::appLog().trace() << "OnConnect " << client.getConfig()->getInstanceName(); - VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString(); - VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -106,21 +107,21 @@ namespace apps::echo::model::tls { }); client.setOnConnected([&client](SocketConnection* socketConnection) { // onConnected - VLOG(1) << "OnConnected " << client.getConfig()->getInstanceName(); + snode::semantic::appLog().trace() << "OnConnected " << client.getConfig()->getInstanceName(); X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { const long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(1) << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + + snode::semantic::appLog().trace() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); - VLOG(1) << "\t Subject: " + std::string(str); + snode::semantic::appLog().trace() << "\t Subject: " + std::string(str); OPENSSL_free(str); str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0); - VLOG(1) << "\t Issuer: " + std::string(str); + snode::semantic::appLog().trace() << "\t Issuer: " + std::string(str); OPENSSL_free(str); // We could do all sorts of certificate verification stuff here before deallocating the certificate. @@ -130,21 +131,21 @@ namespace apps::echo::model::tls { const int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - VLOG(1) << "\t Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - VLOG(1) << "\t SAN (URI): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (URI): '" + subjectAltName; } else if (generalName->type == GEN_DNS) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.dNSName)), static_cast(ASN1_STRING_length(generalName->d.dNSName))); - VLOG(1) << "\t SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (DNS): '" + subjectAltName; } else { - VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -152,15 +153,15 @@ namespace apps::echo::model::tls { X509_free(server_cert); } else { - VLOG(1) << "\tPeer certificate: no certificate"; + snode::semantic::appLog().trace() << "\tPeer certificate: no certificate"; } }); client.setOnDisconnect([&client](SocketConnection* socketConnection) { // onDisconnect - VLOG(1) << "OnDisconnect " << client.getConfig()->getInstanceName(); + snode::semantic::appLog().trace() << "OnDisconnect " << client.getConfig()->getInstanceName(); - VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString(); - VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); return client; diff --git a/src/apps/echo/model/servers.h b/src/apps/echo/model/servers.h index 684c1f4527..48fc29668f 100644 --- a/src/apps/echo/model/servers.h +++ b/src/apps/echo/model/servers.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -90,10 +91,10 @@ namespace apps::echo::model::tls { EchoSocketServer server("echoserver"); server.setOnConnect([&server](SocketConnection* socketConnection) { // onConnect - VLOG(1) << "OnConnect " << server.getConfig()->getInstanceName(); + snode::semantic::appLog().trace() << "OnConnect " << server.getConfig()->getInstanceName(); - VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString(); - VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -106,21 +107,21 @@ namespace apps::echo::model::tls { }); server.setOnConnected([&server](SocketConnection* socketConnection) { // onConnected - VLOG(1) << "OnConnected " << server.getConfig()->getInstanceName(); + snode::semantic::appLog().trace() << "OnConnected " << server.getConfig()->getInstanceName(); X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(1) << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + + snode::semantic::appLog().trace() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); - VLOG(1) << "\t Subject: " + std::string(str); + snode::semantic::appLog().trace() << "\t Subject: " + std::string(str); OPENSSL_free(str); str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0); - VLOG(1) << "\t Issuer: " + std::string(str); + snode::semantic::appLog().trace() << "\t Issuer: " + std::string(str); OPENSSL_free(str); // We could do all sorts of certificate verification stuff here before deallocating the certificate. @@ -130,21 +131,21 @@ namespace apps::echo::model::tls { int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - VLOG(1) << "\t Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - VLOG(1) << "\t SAN (URI): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (URI): '" + subjectAltName; } else if (generalName->type == GEN_DNS) { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.dNSName)), static_cast(ASN1_STRING_length(generalName->d.dNSName))); - VLOG(1) << "\t SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (DNS): '" + subjectAltName; } else { - VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -152,15 +153,15 @@ namespace apps::echo::model::tls { X509_free(server_cert); } else { - VLOG(1) << "\tPeer certificate: no certificate"; + snode::semantic::appLog().trace() << "\tPeer certificate: no certificate"; } }); server.setOnDisconnect([&server](SocketConnection* socketConnection) { // onDisconnect - VLOG(1) << "OnDisconnect " << server.getConfig()->getInstanceName(); + snode::semantic::appLog().trace() << "OnDisconnect " << server.getConfig()->getInstanceName(); - VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString(); - VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); return server; diff --git a/src/apps/express_compat_server.cpp b/src/apps/express_compat_server.cpp index cf0d7b7f9c..5c5cd0d7cb 100644 --- a/src/apps/express_compat_server.cpp +++ b/src/apps/express_compat_server.cpp @@ -1,3 +1,4 @@ +#include /* * Express compatibility server for SNode.C/Express * @@ -237,16 +238,16 @@ int main(int argc, char* argv[]) { app.listen(8080, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "express-compat listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "express-compat listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "express-compat disabled"; + snode::semantic::appLog().trace() << "express-compat disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << "express-compat " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << "express-compat " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << "express-compat " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << "express-compat " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/http/httpclient.cpp b/src/apps/http/httpclient.cpp index 2d9533ee3c..95479b23bb 100644 --- a/src/apps/http/httpclient.cpp +++ b/src/apps/http/httpclient.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -60,16 +61,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -101,7 +102,7 @@ core::socket::State& state) { #elif (NET_TYPE == RC) // rf // client.connect("A4:B1:C1:2C:82:37", 1, "44:01:BB:A3:63:32", [](const SocketAddress& socketAddress, const core::socket::State& state) { client.connect("10:3D:1C:AC:BA:9C", 1, "44:01:BB:A3:63:32", [](const SocketAddress& socketAddress, const core::socket::State& state) { #elif (NET_TYPE == UN) // un client.connect("/tmp/testme", [](const SocketAddress& socketAddress, const -core::socket::State& state) { #endif if (errnum != 0) { PLOG(ERROR) << "OnError: " << errnum; } else { VLOG(1) << "snode.c +core::socket::State& state) { #endif if (errnum != 0) { snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << errnum; } else { snode::semantic::appLog().trace() << "snode.c connecting to " << socketAddress.toString(); } diff --git a/src/apps/http/httplowlevelclient.cpp b/src/apps/http/httplowlevelclient.cpp index 59423321c5..f9096e7399 100644 --- a/src/apps/http/httplowlevelclient.cpp +++ b/src/apps/http/httplowlevelclient.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -69,13 +70,13 @@ namespace apps::http { web::http::client::ResponseParser* responseParser = new web::http::client::ResponseParser( socketContext, []() { - VLOG(1) << "++ OnStarted"; + snode::semantic::appLog().trace() << "++ OnStarted"; }, []([[maybe_unused]] web::http::client::Response& res) { - VLOG(1) << "++ OnParsed"; + snode::semantic::appLog().trace() << "++ OnParsed"; }, [](int status, const std::string& reason) { - VLOG(1) << "++ OnError: " + std::to_string(status) + " - " + reason; + snode::semantic::appLog().trace() << "++ OnError: " + std::to_string(status) + " - " + reason; }); return responseParser; @@ -91,10 +92,10 @@ namespace apps::http { ~SimpleSocketProtocol() override; void onConnected() override { - VLOG(1) << "SimpleSocketProtocol connected"; + snode::semantic::appLog().trace() << "SimpleSocketProtocol connected"; } void onDisconnected() override { - VLOG(1) << "SimpleSocketProtocol disconnected"; + snode::semantic::appLog().trace() << "SimpleSocketProtocol disconnected"; } bool onSignal([[maybe_unused]] int signum) override { @@ -148,10 +149,10 @@ namespace tls { SocketClient tlsClient( "tls", [](SocketConnection* socketConnection) { // onConnect - VLOG(1) << "OnConnect"; + snode::semantic::appLog().trace() << "OnConnect"; - VLOG(1) << "\tServer: " << socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " << socketConnection->getLocalAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -163,20 +164,20 @@ namespace tls { // } }, [](SocketConnection* socketConnection) { // onConnected - VLOG(1) << "OnConnected"; + snode::semantic::appLog().trace() << "OnConnected"; X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { const long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(1) << " Server certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); + snode::semantic::appLog().trace() << " Server certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); - VLOG(1) << " Subject: " + std::string(str); + snode::semantic::appLog().trace() << " Subject: " + std::string(str); OPENSSL_free(str); str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0); - VLOG(1) << " Issuer: " + std::string(str); + snode::semantic::appLog().trace() << " Issuer: " + std::string(str); OPENSSL_free(str); // We could do all sorts of certificate verification stuff here before deallocating the certificate. @@ -186,21 +187,21 @@ namespace tls { const int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - VLOG(1) << "\t Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - VLOG(1) << "\t SAN (URI): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (URI): '" + subjectAltName; } else if (generalName->type == GEN_DNS) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.dNSName)), static_cast(ASN1_STRING_length(generalName->d.dNSName))); - VLOG(1) << "\t SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (DNS): '" + subjectAltName; } else { - VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -208,16 +209,16 @@ namespace tls { X509_free(server_cert); } else { - VLOG(1) << " Server certificate: no certificate"; + snode::semantic::appLog().trace() << " Server certificate: no certificate"; } socketConnection->sendToPeer("GET /index.html HTTP/1.1\r\nConnection: close\r\n\r\n"); // Connection: close\r\n\r\n"); }, [](SocketConnection* socketConnection) { // onDisconnect - VLOG(1) << "OnDisconnect"; + snode::semantic::appLog().trace() << "OnDisconnect"; - VLOG(1) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); @@ -229,16 +230,16 @@ namespace tls { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -257,29 +258,29 @@ namespace legacy { SocketClient legacyClient( "legacy", [](SocketConnection* socketConnection) { // OnConnect - VLOG(1) << "OnConnect"; + snode::semantic::appLog().trace() << "OnConnect"; - VLOG(1) << "\tServer: " << socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " << socketConnection->getLocalAddress().toString(); }, [](SocketConnection* socketConnection) { // onConnected - VLOG(1) << "OnConnected"; + snode::semantic::appLog().trace() << "OnConnected"; socketConnection->sendToPeer("GET /index.html HTTP/1.1\r\nConnection: close\r\n\r\n"); // Connection: close\r\n\r\n"); }, [](SocketConnection* socketConnection) { // onDisconnect - VLOG(1) << "OnDisconnect"; + snode::semantic::appLog().trace() << "OnDisconnect"; - VLOG(1) << "\tServer: " << socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " << socketConnection->getLocalAddress().toString(); }); SocketAddress remoteAddress("localhost", 8080); remoteAddress.init(); - VLOG(1) << "###############': " << remoteAddress.getCanonName(); - VLOG(1) << "###############': " << remoteAddress.toString(); + snode::semantic::appLog().trace() << "###############': " << remoteAddress.getCanonName(); + snode::semantic::appLog().trace() << "###############': " << remoteAddress.toString(); legacyClient.connect(remoteAddress, [instanceName = legacyClient.getConfig()->getInstanceName()]( @@ -287,16 +288,16 @@ namespace legacy { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -320,16 +321,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -344,16 +345,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/http/httpserver.cpp b/src/apps/http/httpserver.cpp index b941509efe..0dafd9c804 100644 --- a/src/apps/http/httpserver.cpp +++ b/src/apps/http/httpserver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -85,27 +86,27 @@ int main(int argc, char* argv[]) { webApp.getConfig()->addSniCerts(sniCerts); #endif - VLOG(1) << "Routes:"; + snode::semantic::appLog().trace() << "Routes:"; for (std::string& route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } webApp.listen([instanceName = webApp.getConfig()->getInstanceName()](const core::socket::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -138,7 +139,7 @@ state) { // titan #elif (NET_TYPE == RC) // rf // webApp.listen("A4:B1:C1:2C:82:37", 1, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) { // titan webApp.listen("10:3D:1C:AC:BA:9C", 1, 5, [](const WebApp::SocketAddress& socketAddress, const core::socket::State& state) { // titan #elif (NET_TYPE == UN) // un webApp.listen("/tmp/testme", 5, [](const WebApp::SocketAddress& socketAddress, const -core::socket::State& state) { // titan #endif if (errnum != 0) { PLOG(FATAL) << "listen"; } else { VLOG(1) << "snode.c listening on +core::socket::State& state) { // titan #endif if (errnum != 0) { snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Critical, errno) << "listen"; } else { snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } diff --git a/src/apps/http/model/clients.h b/src/apps/http/model/clients.h index edacf58847..748b12bd58 100644 --- a/src/apps/http/model/clients.h +++ b/src/apps/http/model/clients.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -69,7 +70,7 @@ #endif /* DOXYGEN_SHOULD_SKIP_THIS */ static void logResponse(const std::shared_ptr& req, const std::shared_ptr& res) { - VLOG(1) << req->getConnectionName() << " HTTP response: " << req->method << " " << req->url << " HTTP/" << req->httpMajor << "." + snode::semantic::appLog().trace() << req->getConnectionName() << " HTTP response: " << req->method << " " << req->url << " HTTP/" << req->httpMajor << "." << req->httpMinor << "\n" << httputils::toString(req->method, req->url, @@ -97,7 +98,7 @@ namespace apps::http::legacy { Client client( "httpclient", [](const std::shared_ptr& req) { - VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestStart"; + snode::semantic::appLog().trace() << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestStart"; req->httpMajor = 1; req->httpMinor = 1; @@ -121,13 +122,13 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.tt", [req](int ret) { if (ret == 0) { - VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().trace() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - VLOG(1) << " /home/voc/projects/snodec/snode.c/CMakeLists.tt"; + snode::semantic::appLog().trace() << " /home/voc/projects/snodec/snode.c/CMakeLists.tt"; } else { - LOG(ERROR) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - PLOG(ERROR) << " /home/voc/projects/snodec/snode.c/CMakeLists.tt"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << " /home/voc/projects/snodec/snode.c/CMakeLists.tt"; } }, [](const std::shared_ptr& req, const std::shared_ptr& res) { @@ -296,24 +297,24 @@ namespace apps::http::legacy { if (eventStream_1) { eventStream_1->onOpen([]() { - VLOG(0) << "OnOpen 1"; + snode::semantic::appLog().trace() << "OnOpen 1"; }); eventStream_1->onError([]() { - VLOG(0) << "OnError 1"; + snode::semantic::appLog().trace() << "OnError 1"; }); eventStream_1->onMessage([](const web::http::client::tools::EventSource::MessageEvent& message) { - VLOG(0) << "OnMessage 1:1: " << message.data; + snode::semantic::appLog().trace() << "OnMessage 1:1: " << message.data; }); eventStream_1->onMessage([](const web::http::client::tools::EventSource::MessageEvent& message) { - VLOG(0) << "OnMessage 1:2: " << message.data; + snode::semantic::appLog().trace() << "OnMessage 1:2: " << message.data; }); eventStream_1->addEventListener("myevent", [](const web::http::client::tools::EventSource::MessageEvent& message) { - VLOG(0) << "EventListener for 'myevent' 1:1: " << message.lastEventId << " : " << message.data; + snode::semantic::appLog().trace() << "EventListener for 'myevent' 1:1: " << message.lastEventId << " : " << message.data; }); eventStream_1->addEventListener("myevent", [](const web::http::client::tools::EventSource::MessageEvent& message) { - VLOG(0) << "EventListener for 'myevent' 1:2: " << message.lastEventId << " : " << message.data; + snode::semantic::appLog().trace() << "EventListener for 'myevent' 1:2: " << message.lastEventId << " : " << message.data; }); core::timer::Timer::singleshotTimer( @@ -327,24 +328,24 @@ namespace apps::http::legacy { if (eventStream_2) { eventStream_2->onOpen([]() { - VLOG(0) << "OnOpen 2"; + snode::semantic::appLog().trace() << "OnOpen 2"; }); eventStream_2->onError([]() { - VLOG(0) << "OnError 2"; + snode::semantic::appLog().trace() << "OnError 2"; }); eventStream_2->onMessage([](const web::http::client::tools::EventSource::MessageEvent& message) { - VLOG(0) << "OnMessage 2:1: " << message.data; + snode::semantic::appLog().trace() << "OnMessage 2:1: " << message.data; }); eventStream_2->onMessage([](const web::http::client::tools::EventSource::MessageEvent& message) { - VLOG(0) << "OnMessage 2:2: " << message.data; + snode::semantic::appLog().trace() << "OnMessage 2:2: " << message.data; }); eventStream_2->addEventListener("myevent", [](const web::http::client::tools::EventSource::MessageEvent& message) { - VLOG(0) << "EventListener for 'myevent' 2:1: " << message.lastEventId << " : " << message.data; + snode::semantic::appLog().trace() << "EventListener for 'myevent' 2:1: " << message.lastEventId << " : " << message.data; }); eventStream_2->addEventListener("myevent", [](const web::http::client::tools::EventSource::MessageEvent& message) { - VLOG(0) << "EventListener for 'myevent' 2:2: " << message.lastEventId << " : " << message.data; + snode::semantic::appLog().trace() << "EventListener for 'myevent' 2:2: " << message.lastEventId << " : " << message.data; }); } @@ -367,13 +368,13 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.txt", [req](int ret) { if (ret == 0) { - VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().trace() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - VLOG(1) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::semantic::appLog().trace() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } else { - LOG(ERROR) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - PLOG(ERROR) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } }, [&req](const std::shared_ptr& reqa, const std::shared_ptr& res) { @@ -387,13 +388,13 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.txt", [&req](int ret) { if (ret == 0) { - VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().trace() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - VLOG(1) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::semantic::appLog().trace() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } else { - LOG(ERROR) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - PLOG(ERROR) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } }, [](const std::shared_ptr& req, const std::shared_ptr& res) { @@ -423,13 +424,13 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.txt", [req](int ret) { if (ret == 0) { - VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().trace() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - VLOG(1) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::semantic::appLog().trace() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } else { - LOG(ERROR) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - PLOG(ERROR) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } }, [](const std::shared_ptr& req, const std::shared_ptr& res) { @@ -448,13 +449,13 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.txt", [req](int ret) { if (ret == 0) { - VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().trace() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - VLOG(1) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::semantic::appLog().trace() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } else { - LOG(ERROR) << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - PLOG(ERROR) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } }, [](const std::shared_ptr& req, const std::shared_ptr& res) { @@ -467,21 +468,21 @@ namespace apps::http::legacy { #endif }, []([[maybe_unused]] const std::shared_ptr& req) { - VLOG(1) << req->getConnectionName() << ": OnRequestEnd"; + snode::semantic::appLog().trace() << req->getConnectionName() << ": OnRequestEnd"; }); client.setOnConnect([](SocketConnection* socketConnection) { // onConnect - VLOG(1) << socketConnection->getConnectionName() << ": OnConnect"; + snode::semantic::appLog().trace() << socketConnection->getConnectionName() << ": OnConnect"; - VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString(); - VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); client.setOnDisconnect([](SocketConnection* socketConnection) { // onDisconnect - VLOG(1) << socketConnection->getConnectionName() << ": OnDisconnect"; + snode::semantic::appLog().trace() << socketConnection->getConnectionName() << ": OnDisconnect"; - VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString(); - VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); return client; @@ -505,7 +506,7 @@ namespace apps::http::tls { Client client( "httpclient", [](const std::shared_ptr& req) { - VLOG(1) << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestStart"; + snode::semantic::appLog().trace() << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestStart"; req->url = "/"; req->set("Connection", "keep-alive"); @@ -653,14 +654,14 @@ namespace apps::http::tls { }); }, []([[maybe_unused]] const std::shared_ptr& req) { - VLOG(1) << req->getConnectionName() << ": OnRequestEnd"; + snode::semantic::appLog().trace() << req->getConnectionName() << ": OnRequestEnd"; }); client.setOnConnect([](SocketConnection* socketConnection) { // onConnect - VLOG(1) << "OnConnect " << socketConnection->getConnectionName(); + snode::semantic::appLog().trace() << "OnConnect " << socketConnection->getConnectionName(); - VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString(); - VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -673,20 +674,20 @@ namespace apps::http::tls { }); client.setOnConnected([](SocketConnection* socketConnection) { // onConnected - VLOG(1) << socketConnection->getConnectionName() << ": OnConnected"; + snode::semantic::appLog().trace() << socketConnection->getConnectionName() << ": OnConnected"; X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(1) << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + + snode::semantic::appLog().trace() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); - VLOG(1) << "\t Subject: " + std::string(str); + snode::semantic::appLog().trace() << "\t Subject: " + std::string(str); OPENSSL_free(str); str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0); - VLOG(1) << "\t Issuer: " + std::string(str); + snode::semantic::appLog().trace() << "\t Issuer: " + std::string(str); OPENSSL_free(str); // We could do all sorts of certificate verification stuff here before deallocating the certificate. @@ -696,21 +697,21 @@ namespace apps::http::tls { int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - VLOG(1) << "\t Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - VLOG(1) << "\t SAN (URI): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (URI): '" + subjectAltName; } else if (generalName->type == GEN_DNS) { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.dNSName)), static_cast(ASN1_STRING_length(generalName->d.dNSName))); - VLOG(1) << "\t SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (DNS): '" + subjectAltName; } else { - VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -718,15 +719,15 @@ namespace apps::http::tls { X509_free(server_cert); } else { - VLOG(1) << "\tPeer certificate: no certificate"; + snode::semantic::appLog().trace() << "\tPeer certificate: no certificate"; } }); client.setOnDisconnect([](SocketConnection* socketConnection) { // onDisconnect - VLOG(1) << socketConnection->getConnectionName() << ": OnDisconnect"; + snode::semantic::appLog().trace() << socketConnection->getConnectionName() << ": OnDisconnect"; - VLOG(1) << "\tLocal: " << socketConnection->getLocalAddress().toString(); - VLOG(1) << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); return client; diff --git a/src/apps/http/model/servers.h b/src/apps/http/model/servers.h index 871fdb349c..473d576932 100644 --- a/src/apps/http/model/servers.h +++ b/src/apps/http/model/servers.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -99,10 +100,10 @@ namespace apps::http::tls { const std::string& instanceName = webApp.getConfig()->getInstanceName(); webApp.setOnConnect([instanceName](SocketConnection* socketConnection) { // onConnect - VLOG(1) << "OnConnect " << instanceName; + snode::semantic::appLog().trace() << "OnConnect " << instanceName; - VLOG(1) << " Local: " << socketConnection->getLocalAddress().toString(); - VLOG(1) << " Peer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << " Local: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << " Peer: " << socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -115,21 +116,21 @@ namespace apps::http::tls { }); webApp.setOnConnected([instanceName](SocketConnection* socketConnection) { // onConnected - VLOG(1) << "OnConnected " << instanceName; + snode::semantic::appLog().trace() << "OnConnected " << instanceName; X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(1) << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + + snode::semantic::appLog().trace() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); - VLOG(1) << "\t Subject: " + std::string(str); + snode::semantic::appLog().trace() << "\t Subject: " + std::string(str); OPENSSL_free(str); str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0); - VLOG(1) << "\t Issuer: " + std::string(str); + snode::semantic::appLog().trace() << "\t Issuer: " + std::string(str); OPENSSL_free(str); // We could do all sorts of certificate verification stuff here before deallocating the certificate. @@ -139,7 +140,7 @@ namespace apps::http::tls { int32_t altNameCount = OPENSSL_sk_num(reinterpret_cast(subjectAltNames)); - VLOG(1) << "\t Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); @@ -147,14 +148,14 @@ namespace apps::http::tls { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - VLOG(1) << "\t SAN (URI): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (URI): '" + subjectAltName; } else if (generalName->type == GEN_DNS) { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.dNSName)), static_cast(ASN1_STRING_length(generalName->d.dNSName))); - VLOG(1) << "\t SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (DNS): '" + subjectAltName; } else { - VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -162,25 +163,25 @@ namespace apps::http::tls { X509_free(server_cert); } else { - LOG(WARNING) << "\tPeer certificate: no certificate"; + snode::semantic::appLog().warn() << "\tPeer certificate: no certificate"; } }); webApp.setOnDisconnect([instanceName](SocketConnection* socketConnection) { // onDisconnect - VLOG(1) << "OnDisconnect " << instanceName; + snode::semantic::appLog().trace() << "OnDisconnect " << instanceName; - VLOG(2) << " Local: " << socketConnection->getLocalAddress().toString(false); - VLOG(2) << " Peer: " << socketConnection->getRemoteAddress().toString(false); + snode::semantic::appLog().trace() << " Local: " << socketConnection->getLocalAddress().toString(false); + snode::semantic::appLog().trace() << " Peer: " << socketConnection->getRemoteAddress().toString(false); - VLOG(2) << " Online Since: " << socketConnection->getOnlineSince(); - VLOG(2) << " Online Duration: " << socketConnection->getOnlineDuration(); + snode::semantic::appLog().trace() << " Online Since: " << socketConnection->getOnlineSince(); + snode::semantic::appLog().trace() << " Online Duration: " << socketConnection->getOnlineDuration(); - VLOG(2) << " Total Queued: " << socketConnection->getTotalQueued(); - VLOG(2) << " Total Sent: " << socketConnection->getTotalSent(); - VLOG(2) << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent(); - VLOG(2) << " Total Read: " << socketConnection->getTotalRead(); - VLOG(2) << " Total Processed: " << socketConnection->getTotalProcessed(); - VLOG(2) << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed(); + snode::semantic::appLog().trace() << " Total Queued: " << socketConnection->getTotalQueued(); + snode::semantic::appLog().trace() << " Total Sent: " << socketConnection->getTotalSent(); + snode::semantic::appLog().trace() << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent(); + snode::semantic::appLog().trace() << " Total Read: " << socketConnection->getTotalRead(); + snode::semantic::appLog().trace() << " Total Processed: " << socketConnection->getTotalProcessed(); + snode::semantic::appLog().trace() << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed(); }); return webApp; diff --git a/src/apps/http/testbasicauthentication.cpp b/src/apps/http/testbasicauthentication.cpp index a7baa911ea..1da6c61839 100644 --- a/src/apps/http/testbasicauthentication.cpp +++ b/src/apps/http/testbasicauthentication.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -97,16 +98,16 @@ int main(int argc, char* argv[]) { const legacy::in6::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -133,17 +134,17 @@ int main(int argc, char* argv[]) { tlsServer.listen(8088, [](const legacy::in6::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "tls: listening on '" << socketAddress.toString() << "'" + snode::semantic::appLog().trace() << "tls: listening on '" << socketAddress.toString() << "'" << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "tls: disabled"; + snode::semantic::appLog().trace() << "tls: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "tls: error occurred"; + snode::semantic::appLog().trace() << "tls: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "tls: fatal error occurred"; + snode::semantic::appLog().trace() << "tls: fatal error occurred"; break; } }); diff --git a/src/apps/http/testexpressnext.cpp b/src/apps/http/testexpressnext.cpp index 2c3292930a..8fc3967be7 100644 --- a/src/apps/http/testexpressnext.cpp +++ b/src/apps/http/testexpressnext.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -99,7 +100,7 @@ class NextTester { [this](const Client::SocketAddress&, const core::socket::State& state) { if (state != core::socket::State::OK) { ++failures; - LOG(ERROR) << "FAIL: connect failed: " << state.what(); + snode::semantic::appLog().error() << "FAIL: connect failed: " << state.what(); core::timer::Timer::singleshotTimer( [] { core::SNodeC::stop(); @@ -121,7 +122,7 @@ class NextTester { void dispatchNextRequest() { if (testCases.empty()) { - LOG(INFO) << "All express next() tests executed. failures=" << failures; + snode::semantic::appLog().info() << "All express next() tests executed. failures=" << failures; if (masterRequest && masterRequest->isConnected()) { masterRequest->disconnect(); } @@ -135,7 +136,7 @@ class NextTester { if (!masterRequest || !masterRequest->isConnected()) { ++failures; - LOG(ERROR) << "FAIL: master request not connected"; + snode::semantic::appLog().error() << "FAIL: master request not connected"; core::timer::Timer::singleshotTimer( [] { core::SNodeC::stop(); @@ -158,10 +159,10 @@ class NextTester { const bool bodyOk = body.find(current.expectedBody) != std::string::npos; if (statusOk && bodyOk) { - LOG(INFO) << "PASS: " << current.name << " status=" << res->statusCode << " body='" << body << "'"; + snode::semantic::appLog().info() << "PASS: " << current.name << " status=" << res->statusCode << " body='" << body << "'"; } else { ++failures; - LOG(ERROR) << "FAIL: " << current.name << " expected status=" << current.expectedStatus << " expected body fragment='" + snode::semantic::appLog().error() << "FAIL: " << current.name << " expected status=" << current.expectedStatus << " expected body fragment='" << current.expectedBody << "'" << " got status=" << res->statusCode << " body='" << body << "'"; } @@ -170,7 +171,7 @@ class NextTester { }, [this, current]([[maybe_unused]] const std::shared_ptr& req, const std::string& reason) { ++failures; - LOG(ERROR) << "FAIL: " << current.name << " parse-error: " << reason; + snode::semantic::appLog().error() << "FAIL: " << current.name << " parse-error: " << reason; dispatchNextRequest(); }); } @@ -301,16 +302,16 @@ int main(int argc, char* argv[]) { app.listen(18080, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "testexpressnext listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "testexpressnext listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "testexpressnext disabled"; + snode::semantic::appLog().trace() << "testexpressnext disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << "testexpressnext " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << "testexpressnext " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << "testexpressnext " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << "testexpressnext " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -324,10 +325,10 @@ int main(int argc, char* argv[]) { const int rc = core::SNodeC::start(); if (nextTester.getFailures() > 0) { - LOG(ERROR) << "testexpressnext finished with failures=" << nextTester.getFailures(); + snode::semantic::appLog().error() << "testexpressnext finished with failures=" << nextTester.getFailures(); return 1; } - LOG(INFO) << "testexpressnext finished successfully"; + snode::semantic::appLog().info() << "testexpressnext finished successfully"; return rc; } diff --git a/src/apps/http/verysimpleserver.cpp b/src/apps/http/verysimpleserver.cpp index b86cd6a8be..042c20ca1c 100644 --- a/src/apps/http/verysimpleserver.cpp +++ b/src/apps/http/verysimpleserver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -69,16 +70,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << " disabled"; + snode::semantic::appLog().trace() << instanceName << " disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -101,16 +102,16 @@ int main(int argc, char* argv[]) { [instanceName = legacyApp.getConfig()->getInstanceName()](const TLSSocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << " disabled"; + snode::semantic::appLog().trace() << instanceName << " disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/http/vhostserver.cpp b/src/apps/http/vhostserver.cpp index 67df8d029a..630c768f9e 100644 --- a/src/apps/http/vhostserver.cpp +++ b/src/apps/http/vhostserver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -121,16 +122,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << " disabled"; + snode::semantic::appLog().trace() << instanceName << " disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -190,16 +191,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << " disabled"; + snode::semantic::appLog().trace() << instanceName << " disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/jsonclient.cpp b/src/apps/jsonclient.cpp index 1bc844a219..c15e7952e5 100644 --- a/src/apps/jsonclient.cpp +++ b/src/apps/jsonclient.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -60,7 +61,7 @@ int main(int argc, char* argv[]) { const Client jsonClient( "legacy", [](const std::shared_ptr& req) { - VLOG(1) << "-- OnRequest"; + snode::semantic::appLog().trace() << "-- OnRequest"; req->method = "POST"; req->url = "/index.html"; req->type("application/json"); @@ -68,34 +69,34 @@ int main(int argc, char* argv[]) { req->send( R"({"userId":1,"schnitzel":"good","hungry":false})", []([[maybe_unused]] const std::shared_ptr& req, const std::shared_ptr& res) { - VLOG(1) << "-- OnResponse"; - VLOG(1) << " Status:"; - VLOG(1) << " " << res->httpVersion; - VLOG(1) << " " << res->statusCode; - VLOG(1) << " " << res->reason; + snode::semantic::appLog().trace() << "-- OnResponse"; + snode::semantic::appLog().trace() << " Status:"; + snode::semantic::appLog().trace() << " " << res->httpVersion; + snode::semantic::appLog().trace() << " " << res->statusCode; + snode::semantic::appLog().trace() << " " << res->reason; - VLOG(1) << " Headers:"; + snode::semantic::appLog().trace() << " Headers:"; for (const auto& [field, value] : res->headers) { - VLOG(1) << " " << field + " = " + value; + snode::semantic::appLog().trace() << " " << field + " = " + value; } - VLOG(1) << " Cookies:"; + snode::semantic::appLog().trace() << " Cookies:"; for (const auto& [name, cookie] : res->cookies) { - VLOG(1) << " " + name + " = " + cookie.getValue(); + snode::semantic::appLog().trace() << " " + name + " = " + cookie.getValue(); for (const auto& [option, value] : cookie.getOptions()) { - VLOG(1) << " " + option + " = " + value; + snode::semantic::appLog().trace() << " " + option + " = " + value; } } res->body.push_back(0); - VLOG(1) << " Body:\n----------- start body -----------" << res->body.data() << "------------ end body ------------"; + snode::semantic::appLog().trace() << " Body:\n----------- start body -----------" << res->body.data() << "------------ end body ------------"; }, [](const std::shared_ptr&, const std::string& message) { - VLOG(1) << "legacy: Request parse error: " << message; + snode::semantic::appLog().trace() << "legacy: Request parse error: " << message; }); }, []([[maybe_unused]] const std::shared_ptr& req) { - LOG(INFO) << " -- OnRequestEnd"; + snode::semantic::appLog().info() << " -- OnRequestEnd"; }); jsonClient.connect("localhost", @@ -105,16 +106,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { // example.com:81 simulate connect timeout switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -126,16 +127,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -143,7 +144,7 @@ int main(int argc, char* argv[]) { /* jsonClient.post("localhost", 8080, "/index.html", "{\"userId\":1,\"schnitzel\":\"good\",\"hungry\":false}", [](int err) { if (err != 0) { - PLOG(ERROR) << "OnError: " << err; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << err; } }); */ diff --git a/src/apps/jsonserver.cpp b/src/apps/jsonserver.cpp index 2bac44b4e2..e36aec36f9 100644 --- a/src/apps/jsonserver.cpp +++ b/src/apps/jsonserver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -68,16 +69,16 @@ int main(int argc, char* argv[]) { [instanceName = legacyApp.getConfig()->getInstanceName()](const SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -88,10 +89,10 @@ int main(int argc, char* argv[]) { req->getAttribute( [&jsonString](nlohmann::json& json) { jsonString = json.dump(4); - VLOG(1) << "Application received body: " << jsonString; + snode::semantic::appLog().trace() << "Application received body: " << jsonString; }, [](const std::string& key) { - VLOG(1) << key << " attribute not found"; + snode::semantic::appLog().trace() << key << " attribute not found"; }); res->send(jsonString); diff --git a/src/apps/main.cpp b/src/apps/main.cpp index 6f0e89a8a0..d259ce4533 100644 --- a/src/apps/main.cpp +++ b/src/apps/main.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -236,16 +237,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << " disabled"; + snode::semantic::appLog().trace() << instanceName << " disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/oauth2/authorization_server/AuthorizationServer.cpp b/src/apps/oauth2/authorization_server/AuthorizationServer.cpp index 3366098618..0c8c64b97c 100644 --- a/src/apps/oauth2/authorization_server/AuthorizationServer.cpp +++ b/src/apps/oauth2/authorization_server/AuthorizationServer.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -105,11 +106,11 @@ int main(int argc, char* argv[]) { }; database::mariadb::MariaDBClient db{details, [](const database::mariadb::MariaDBState& state) { if (state.error != 0) { - VLOG(0) << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; + snode::semantic::appLog().trace() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; } else if (state.connected) { - VLOG(0) << "MySQL connected"; + snode::semantic::appLog().trace() << "MySQL connected"; } else { - VLOG(0) << "MySQL disconnected"; + snode::semantic::appLog().trace() << "MySQL disconnected"; } }}; @@ -126,17 +127,17 @@ int main(int argc, char* argv[]) { [req, res, next, queryClientId](const MYSQL_ROW row) { if (row != nullptr) { if (std::stoi(row[0]) > 0) { - VLOG(1) << "Valid client id '" << queryClientId << "'"; - VLOG(1) << "Next with " << req->httpVersion << " " << req->method << " " << req->url; + snode::semantic::appLog().trace() << "Valid client id '" << queryClientId << "'"; + snode::semantic::appLog().trace() << "Next with " << req->httpVersion << " " << req->method << " " << req->url; next(); } else { - VLOG(1) << "Invalid client id '" << queryClientId << "'"; + snode::semantic::appLog().trace() << "Invalid client id '" << queryClientId << "'"; res->sendStatus(401); } } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } else { @@ -154,14 +155,14 @@ int main(int argc, char* argv[]) { const std::string paramScope{req->query("scope")}; const std::string paramState{req->query("state")}; - VLOG(1) << "Query params: " + snode::semantic::appLog().trace() << "Query params: " << "response_type=" << req->query("response_type") << ", " << "redirect_uri=" << req->query("redirect_uri") << ", " << "scope=" << req->query("scope") << ", " << "state=" << req->query("state") << "\n"; if (paramResponseType != "code") { - VLOG(1) << "Auth invalid, sending Bad Request"; + snode::semantic::appLog().trace() << "Auth invalid, sending Bad Request"; res->sendStatus(400); return; } @@ -170,10 +171,10 @@ int main(int argc, char* argv[]) { db.exec( "update client set redirect_uri = '" + paramRedirectUri + "' where uuid = '" + paramClientId + "'", [paramRedirectUri]() { - VLOG(1) << "Database: Set redirect_uri to " << paramRedirectUri; + snode::semantic::appLog().trace() << "Database: Set redirect_uri to " << paramRedirectUri; }, [](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; }); } @@ -181,10 +182,10 @@ int main(int argc, char* argv[]) { db.exec( "update client set scope = '" + paramScope + "' where uuid = '" + paramClientId + "'", [paramScope]() { - VLOG(1) << "Database: Set scope to " << paramScope; + snode::semantic::appLog().trace() << "Database: Set scope to " << paramScope; }, [](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; }); } @@ -192,14 +193,14 @@ int main(int argc, char* argv[]) { db.exec( "update client set state = '" + paramState + "' where uuid = '" + paramClientId + "'", [paramState]() { - VLOG(1) << "Database: Set state to " << paramState; + snode::semantic::appLog().trace() << "Database: Set state to " << paramState; }, [](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; }); } - VLOG(1) << "Auth request valid, redirecting to login"; + snode::semantic::appLog().trace() << "Auth request valid, redirecting to login"; std::string loginUri{"/oauth2/login"}; addQueryParamToUri(loginUri, "client_id", paramClientId); res->redirect(loginUri); @@ -209,7 +210,7 @@ int main(int argc, char* argv[]) { res->sendFile("/home/rathalin/projects/snode.c/src/oauth2/authorization_server/vue-frontend-oauth2-auth-server/dist/index.html", [req](int ret) { if (ret != 0) { - PLOG(ERROR) << req->url; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << req->url; } }); }); @@ -248,7 +249,7 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) .query( @@ -273,24 +274,24 @@ int main(int argc, char* argv[]) { res->set("Access-Control-Allow-Origin", "*"); const nlohmann::json responseJson = {{"redirect_uri", clientRedirectUri}}; const std::string responseJsonString{responseJson.dump(4)}; - VLOG(1) << "Sending json reponse: " << responseJsonString; + snode::semantic::appLog().trace() << "Sending json reponse: " << responseJsonString; res->send(responseJsonString); }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); }, @@ -302,11 +303,11 @@ int main(int argc, char* argv[]) { router.get("/token", [&db] APPLICATION(req, res) { res->set("Access-Control-Allow-Origin", "*"); auto queryGrantType = req->query("grant_type"); - VLOG(1) << "GrandType: " << queryGrantType; + snode::semantic::appLog().trace() << "GrandType: " << queryGrantType; auto queryCode = req->query("code"); - VLOG(1) << "Code: " << queryCode; + snode::semantic::appLog().trace() << "Code: " << queryCode; auto queryRedirectUri = req->query("redirect_uri"); - VLOG(1) << "RedirectUri: " << queryRedirectUri; + snode::semantic::appLog().trace() << "RedirectUri: " << queryRedirectUri; if (queryGrantType != "authorization_code") { res->status(400).send("Invalid query parameter 'grant_type', value must be 'authorization_code'"); return; @@ -365,7 +366,7 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) .query( @@ -382,13 +383,13 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) .exec( @@ -401,7 +402,7 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) .query( @@ -424,26 +425,26 @@ int main(int argc, char* argv[]) { res->send(jsonResponseString); }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); }); @@ -451,13 +452,13 @@ int main(int argc, char* argv[]) { router.post("/token/refresh", [&db] APPLICATION(req, res) { res->set("Access-Control-Allow-Origin", "*"); auto queryClientId = req->query("client_id"); - VLOG(1) << "ClientId: " << queryClientId; + snode::semantic::appLog().trace() << "ClientId: " << queryClientId; auto queryGrantType = req->query("grant_type"); - VLOG(1) << "GrandType: " << queryGrantType; + snode::semantic::appLog().trace() << "GrandType: " << queryGrantType; auto queryRefreshToken = req->query("refresh_token"); - VLOG(1) << "RefreshToken: " << queryRefreshToken; + snode::semantic::appLog().trace() << "RefreshToken: " << queryRefreshToken; auto queryState = req->query("state"); - VLOG(1) << "State: " << queryState; + snode::semantic::appLog().trace() << "State: " << queryState; if (queryGrantType.length() == 0) { res->status(400).send("Missing query parameter 'grant_type'"); return; @@ -498,7 +499,7 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) .query( @@ -518,34 +519,34 @@ int main(int argc, char* argv[]) { res->send(responseJson.dump(4)); }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); }); router.post("/token/validate", [&db] APPLICATION(req, res) { - VLOG(1) << "POST /token/validate"; + snode::semantic::appLog().trace() << "POST /token/validate"; req->getAttribute([res, &db](nlohmann::json& jsonBody) { if (!jsonBody.contains("access_token")) { - VLOG(1) << "Missing 'access_token' in json"; + snode::semantic::appLog().trace() << "Missing 'access_token' in json"; res->status(500).send("Missing 'access_token' in json"); return; } const std::string jsonAccessToken{jsonBody["access_token"]}; if (!jsonBody.contains("client_id")) { - VLOG(1) << "Missing 'client_id' in json"; + snode::semantic::appLog().trace() << "Missing 'client_id' in json"; res->status(500).send("Missing 'client_id' in json"); return; } @@ -564,17 +565,17 @@ int main(int argc, char* argv[]) { if (row != nullptr) { if (std::stoi(row[0]) == 0) { const nlohmann::json errorJson = {{"error", "Invalid access token"}}; - VLOG(1) << "Sending 401: Invalid access token '" << jsonAccessToken << "'"; + snode::semantic::appLog().trace() << "Sending 401: Invalid access token '" << jsonAccessToken << "'"; res->status(401).send(errorJson.dump(4)); } else { - VLOG(1) << "Sending 200: Valid access token '" << jsonAccessToken << ""; + snode::semantic::appLog().trace() << "Sending 200: Valid access token '" << jsonAccessToken << ""; const nlohmann::json successJson = {{"success", "Valid access token"}}; res->status(200).send(successJson.dump(4)); } } }, [res](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); }); @@ -587,16 +588,16 @@ int main(int argc, char* argv[]) { app.listen(8082, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "OAuth2AuthorizationServer: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "OAuth2AuthorizationServer: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "OAuth2AuthorizationServer: disabled"; + snode::semantic::appLog().trace() << "OAuth2AuthorizationServer: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "OAuth2AuthorizationServer: error occurred"; + snode::semantic::appLog().trace() << "OAuth2AuthorizationServer: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "OAuth2AuthorizationServer: fatal error occurred"; + snode::semantic::appLog().trace() << "OAuth2AuthorizationServer: fatal error occurred"; break; } }); diff --git a/src/apps/oauth2/client_app/ClientApp.cpp b/src/apps/oauth2/client_app/ClientApp.cpp index 460385140f..00ca57a697 100644 --- a/src/apps/oauth2/client_app/ClientApp.cpp +++ b/src/apps/oauth2/client_app/ClientApp.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -53,7 +54,7 @@ int main(int argc, char* argv[]) { res->sendFile("/home/rathalin/projects/snode.c/src/oauth2/client_app/vue-frontend-oauth2-client/dist/index.html", [req](int ret) { if (ret != 0) { - PLOG(ERROR) << req->url; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << req->url; } }); /* @@ -65,7 +66,7 @@ int main(int argc, char* argv[]) { } tokenRequestUri += "&client_id=911a821a-ea2d-11ec-8e2e-08002771075f"; tokenRequestUri += "&redirect_uri=http://localhost:8081/oauth2"; - VLOG(1) << "Recieving auth code from auth server: " << req.query("code") << ", requesting token from " << tokenRequestUri; + snode::semantic::appLog().trace() << "Recieving auth code from auth server: " << req.query("code") << ", requesting token from " << tokenRequestUri; res.redirect(tokenRequestUri); */ } @@ -76,16 +77,16 @@ int main(int argc, char* argv[]) { app.listen(8081, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "OAuth2Client: connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "OAuth2Client: connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "OAuth2Client: disabled"; + snode::semantic::appLog().trace() << "OAuth2Client: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "OAuth2Client: error occurred"; + snode::semantic::appLog().trace() << "OAuth2Client: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "OAuth2Client: fatal error occurred"; + snode::semantic::appLog().trace() << "OAuth2Client: fatal error occurred"; break; } }); diff --git a/src/apps/oauth2/resource_server/ResourceServer.cpp b/src/apps/oauth2/resource_server/ResourceServer.cpp index 3390f9f10c..ff3acc8755 100644 --- a/src/apps/oauth2/resource_server/ResourceServer.cpp +++ b/src/apps/oauth2/resource_server/ResourceServer.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -63,41 +64,41 @@ int main(int argc, char* argv[]) { const std::string queryAccessToken{req->query("access_token")}; const std::string queryClientId{req->query("client_id")}; if (queryAccessToken.empty() || queryClientId.empty()) { - VLOG(1) << "Missing access_token or client_id in body"; + snode::semantic::appLog().trace() << "Missing access_token or client_id in body"; res->sendStatus(401); return; } const web::http::legacy::in::Client legacyClient( [](web::http::legacy::in::Client::SocketConnection* socketConnection) { - VLOG(1) << "OnConnect"; + snode::semantic::appLog().trace() << "OnConnect"; - VLOG(1) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " + socketConnection->getLocalAddress().toString(); }, []([[maybe_unused]] web::http::legacy::in::Client::SocketConnection* socketConnection) { - VLOG(1) << "OnConnected"; + snode::semantic::appLog().trace() << "OnConnected"; }, [](web::http::legacy::in::Client::SocketConnection* socketConnection) { - VLOG(1) << "OnDisconnect"; + snode::semantic::appLog().trace() << "OnDisconnect"; - VLOG(1) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " + socketConnection->getLocalAddress().toString(); }, [queryAccessToken, queryClientId, res](const std::shared_ptr& request) { - VLOG(1) << "OnRequestBegin"; + snode::semantic::appLog().trace() << "OnRequestBegin"; request->url = "/oauth2/token/validate?client_id=" + queryClientId; request->method = "POST"; - VLOG(1) << "ClientId: " << queryClientId; - VLOG(1) << "AccessToken: " << queryAccessToken; + snode::semantic::appLog().trace() << "ClientId: " << queryClientId; + snode::semantic::appLog().trace() << "AccessToken: " << queryAccessToken; const nlohmann::json requestJson = {{"access_token", queryAccessToken}, {"client_id", queryClientId}}; const std::string requestJsonString{requestJson.dump(4)}; request->send( requestJsonString, [res]([[maybe_unused]] const std::shared_ptr& request, const std::shared_ptr& response) { - VLOG(1) << "OnResponse"; - VLOG(1) << "Response: " << std::string(response->body.begin(), response->body.end()); + snode::semantic::appLog().trace() << "OnResponse"; + snode::semantic::appLog().trace() << "Response: " << std::string(response->body.begin(), response->body.end()); if (std::stoi(response->statusCode) != 200) { const nlohmann::json errorJson = {{"error", "Invalid access token"}}; res->status(401).send(errorJson.dump(4)); @@ -107,27 +108,27 @@ int main(int argc, char* argv[]) { } }, [](const std::shared_ptr&, const std::string& message) { - VLOG(1) << "OAuth2ResourceServer: Request parse error: " << message; + snode::semantic::appLog().trace() << "OAuth2ResourceServer: Request parse error: " << message; }); }, []([[maybe_unused]] const std::shared_ptr& req) { - LOG(INFO) << " -- OnRequestEnd"; + snode::semantic::appLog().info() << " -- OnRequestEnd"; }); legacyClient.connect( "localhost", 8082, [](const web::http::legacy::in::Client::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "OAuth2ResourceServer: connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "OAuth2ResourceServer: connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "OAuth2ResourceServer: disabled"; + snode::semantic::appLog().trace() << "OAuth2ResourceServer: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "OAuth2ResourceServer: error occurred"; + snode::semantic::appLog().trace() << "OAuth2ResourceServer: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "OAuth2ResourceServer: fatal error occurred"; + snode::semantic::appLog().trace() << "OAuth2ResourceServer: fatal error occurred"; break; } }); @@ -136,16 +137,16 @@ int main(int argc, char* argv[]) { app.listen(8083, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "app: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "app: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "app: disabled"; + snode::semantic::appLog().trace() << "app: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "app: error occurred"; + snode::semantic::appLog().trace() << "app: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "app: fatal error occurred"; + snode::semantic::appLog().trace() << "app: fatal error occurred"; break; } }); diff --git a/src/apps/testpipe.cpp b/src/apps/testpipe.cpp index e0b72e08ee..46d6d61b9d 100644 --- a/src/apps/testpipe.cpp +++ b/src/apps/testpipe.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -61,28 +62,28 @@ int main(int argc, char* argv[]) { []([[maybe_unused]] core::pipe::PipeSource& pipeSource, [[maybe_unused]] core::pipe::PipeSink& pipeSink) { pipeSink.setOnData([&pipeSource](const char* chunk, std::size_t chunkLen) { const std::string string(chunk, chunkLen); - VLOG(1) << "Pipe Data: " << string; + snode::semantic::appLog().trace() << "Pipe Data: " << string; pipeSource.send(chunk, chunkLen); // pipeSink.disable(); // pipeSource.disable(); }); pipeSink.setOnEof([]() { - VLOG(1) << "Pipe EOF"; + snode::semantic::appLog().trace() << "Pipe EOF"; }); pipeSink.setOnError([]([[maybe_unused]] int errnum) { - VLOG(1) << "PipeSink"; + snode::semantic::appLog().trace() << "PipeSink"; }); pipeSource.setOnError([]([[maybe_unused]] int errnum) { - VLOG(1) << "PipeSource"; + snode::semantic::appLog().trace() << "PipeSource"; }); pipeSource.send("Hello World!"); }, []([[maybe_unused]] int errnum) { - PLOG(ERROR) << "Pipe not created"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "Pipe not created"; }); return core::SNodeC::start(); diff --git a/src/apps/testpost.cpp b/src/apps/testpost.cpp index 7d5a060010..d17820ea74 100644 --- a/src/apps/testpost.cpp +++ b/src/apps/testpost.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -107,16 +108,16 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const LegacySocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "legacyApp: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "legacyApp: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "legacyApp: disabled"; + snode::semantic::appLog().trace() << "legacyApp: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "legacyApp: error occurred"; + snode::semantic::appLog().trace() << "legacyApp: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "legacyApp: fatal error occurred"; + snode::semantic::appLog().trace() << "legacyApp: fatal error occurred"; break; } }); @@ -137,16 +138,16 @@ int main(int argc, char* argv[]) { tlsApp.listen("localhost", 8088, [](const TLSSocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "tlsApp: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "tlsApp: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "tlsApp: disabled"; + snode::semantic::appLog().trace() << "tlsApp: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "tlsApp: error occurred"; + snode::semantic::appLog().trace() << "tlsApp: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "tlsApp: fatal error occurred"; + snode::semantic::appLog().trace() << "tlsApp: fatal error occurred"; break; } }); diff --git a/src/apps/testregex.cpp b/src/apps/testregex.cpp index 46f6213f15..012db50491 100644 --- a/src/apps/testregex.cpp +++ b/src/apps/testregex.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -104,11 +105,11 @@ Router router(database::mariadb::MariaDBClient& db) { .get( "/query/:userId", [] MIDDLEWARE(req, res, next) { - VLOG(1) << "Move on to the next route to query database"; + snode::semantic::appLog().trace() << "Move on to the next route to query database"; next(); }, [&db] MIDDLEWARE(req, res, next) { // http://localhost:8080/query/123 - VLOG(1) << "UserId: " << req->params["userId"]; + snode::semantic::appLog().trace() << "UserId: " << req->params["userId"]; std::string userId = req->params["userId"]; req->setAttribute(std::string()); @@ -159,29 +160,29 @@ Router router(database::mariadb::MariaDBClient& db) { " \n" "\n")); }); - VLOG(1) << "Move on to the next route to send result"; + snode::semantic::appLog().trace() << "Move on to the next route to send result"; next(); } }, [res, userId](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error: " << errorString << " : " << errorNumber; res->status(404).send(userId + ": " + errorString + " - " + std::to_string(errorNumber)); }); }, [] MIDDLEWARE(req, res, next) { - VLOG(1) << "And again 1: Move on to the next route to send result"; + snode::semantic::appLog().trace() << "And again 1: Move on to the next route to send result"; next(); }, [] MIDDLEWARE(req, res, next) { - VLOG(1) << "And again 2: Move on to the next route to send result"; + snode::semantic::appLog().trace() << "And again 2: Move on to the next route to send result"; next(); }) .get([] MIDDLEWARE(req, res, next) { - VLOG(1) << "And again 3: Move on to the next route to send result"; + snode::semantic::appLog().trace() << "And again 3: Move on to the next route to send result"; next(); }) .get([] APPLICATION(req, res) { - VLOG(1) << "SendResult"; + snode::semantic::appLog().trace() << "SendResult"; req->getAttribute( [res](std::string& table) { @@ -192,9 +193,9 @@ Router router(database::mariadb::MariaDBClient& db) { }); }); router.get("/account/:userId(\\d*)/:userName", [&db] APPLICATION(req, res) { // http://localhost:8080/account/123/perfectNDSgroup - VLOG(1) << "Show account of"; - VLOG(1) << "UserId: " << req->params["userId"]; - VLOG(1) << "UserName: " << req->params["userName"]; + snode::semantic::appLog().trace() << "Show account of"; + snode::semantic::appLog().trace() << "UserId: " << req->params["userId"]; + snode::semantic::appLog().trace() << "UserName: " << req->params["userName"]; const std::string response = "" " " @@ -219,18 +220,18 @@ Router router(database::mariadb::MariaDBClient& db) { db.exec( "INSERT INTO `snodec`(`username`, `password`) VALUES ('" + userId + "','" + userName + "')", [userId, userName]() { - VLOG(1) << "Inserted: -> " << userId << " - " << userName; + snode::semantic::appLog().trace() << "Inserted: -> " << userId << " - " << userName; }, [](const std::string& errorString, unsigned int errorNumber) { - VLOG(1) << "Error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Error: " << errorString << " : " << errorNumber; }); res->send(response); }); router.get("/asdf/:testRegex1(d\\d{3}e)/jklö/:testRegex2", [] APPLICATION(req, res) { // http://localhost:8080/asdf/d123e/jklö/hallo - VLOG(1) << "Testing Regex"; - VLOG(1) << "Regex1: " << req->params["testRegex1"]; - VLOG(1) << "Regex2: " << req->params["testRegex2"]; + snode::semantic::appLog().trace() << "Testing Regex"; + snode::semantic::appLog().trace() << "Regex1: " << req->params["testRegex1"]; + snode::semantic::appLog().trace() << "Regex2: " << req->params["testRegex2"]; const std::string response = "" " " @@ -252,9 +253,9 @@ Router router(database::mariadb::MariaDBClient& db) { res->send(response); }); router.get("/search/:search", [] APPLICATION(req, res) { // http://localhost:8080/search/buxtehude123 - VLOG(1) << "Show Search of"; - VLOG(1) << "Search: " << req->params["search"]; - VLOG(1) << "Queries: " << req->query("test"); + snode::semantic::appLog().trace() << "Show Search of"; + snode::semantic::appLog().trace() << "Search: " << req->params["search"]; + snode::semantic::appLog().trace() << "Queries: " << req->query("test"); res->send(req->params["search"]); }); @@ -287,11 +288,11 @@ int main(int argc, char* argv[]) { database::mariadb::MariaDBClient db(details, [](const database::mariadb::MariaDBState& state) { if (state.error != 0) { - VLOG(0) << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; + snode::semantic::appLog().trace() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; } else if (state.connected) { - VLOG(0) << "MySQL connected"; + snode::semantic::appLog().trace() << "MySQL connected"; } else { - VLOG(0) << "MySQL disconnected"; + snode::semantic::appLog().trace() << "MySQL disconnected"; } }); @@ -303,32 +304,32 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "legacy-testregex: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "legacy-testregex: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "legacy-testregex: disabled"; + snode::semantic::appLog().trace() << "legacy-testregex: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "legacy-testregex: error occurred"; + snode::semantic::appLog().trace() << "legacy-testregex: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "legacy-testregex: fatal error occurred"; + snode::semantic::appLog().trace() << "legacy-testregex: fatal error occurred"; break; } }); legacyApp.setOnConnect([](legacy::in::WebApp::SocketConnection* socketConnection) { - VLOG(1) << "OnConnect:"; + snode::semantic::appLog().trace() << "OnConnect:"; - VLOG(1) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); legacyApp.setOnDisconnect([](legacy::in::WebApp::SocketConnection* socketConnection) { - VLOG(1) << "OnDisconnect:"; + snode::semantic::appLog().trace() << "OnDisconnect:"; - VLOG(1) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); tls::in::WebApp tlsApp("tls-testregex"); @@ -338,43 +339,43 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const tls::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << "tls-testregex: listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << "tls-testregex: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << "tls-testregex: disabled"; + snode::semantic::appLog().trace() << "tls-testregex: disabled"; break; case core::socket::State::ERROR: - VLOG(1) << "tls-testregex: error occurred"; + snode::semantic::appLog().trace() << "tls-testregex: error occurred"; break; case core::socket::State::FATAL: - VLOG(1) << "tls-testregex: fatal error occurred"; + snode::semantic::appLog().trace() << "tls-testregex: fatal error occurred"; break; } }); tlsApp.setOnConnect([](tls::in::WebApp::SocketConnection* socketConnection) { - VLOG(1) << "OnConnect:"; + snode::semantic::appLog().trace() << "OnConnect:"; - VLOG(1) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); tlsApp.setOnConnected([](tls::in::WebApp::SocketConnection* socketConnection) { - VLOG(1) << "OnConnected:"; + snode::semantic::appLog().trace() << "OnConnected:"; X509* client_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (client_cert != nullptr) { const long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(1) << "\tClient certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); + snode::semantic::appLog().trace() << "\tClient certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(client_cert), nullptr, 0); - VLOG(1) << "\t Subject: " + std::string(str); + snode::semantic::appLog().trace() << "\t Subject: " + std::string(str); OPENSSL_free(str); str = X509_NAME_oneline(X509_get_issuer_name(client_cert), nullptr, 0); - VLOG(1) << "\t Issuer: " + std::string(str); + snode::semantic::appLog().trace() << "\t Issuer: " + std::string(str); OPENSSL_free(str); // We could do all sorts of certificate verification stuff here before deallocating the certificate. @@ -384,21 +385,21 @@ int main(int argc, char* argv[]) { const int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - VLOG(1) << "\t Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - VLOG(1) << "\t SAN (URI): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (URI): '" + subjectAltName; } else if (generalName->type == GEN_DNS) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.dNSName)), static_cast(ASN1_STRING_length(generalName->d.dNSName))); - VLOG(1) << "\t SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (DNS): '" + subjectAltName; } else { - VLOG(1) << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -406,15 +407,15 @@ int main(int argc, char* argv[]) { X509_free(client_cert); } else { - VLOG(1) << "\tClient certificate: no certificate"; + snode::semantic::appLog().trace() << "\tClient certificate: no certificate"; } }); tlsApp.setOnDisconnect([](tls::in::WebApp::SocketConnection* socketConnection) { - VLOG(1) << "OnDisconnect:"; + snode::semantic::appLog().trace() << "OnDisconnect:"; - VLOG(1) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(1) << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); } diff --git a/src/apps/tlslegacy/TlsLegacySocketContext.cpp b/src/apps/tlslegacy/TlsLegacySocketContext.cpp index cdb00d09fc..0aa0577658 100644 --- a/src/apps/tlslegacy/TlsLegacySocketContext.cpp +++ b/src/apps/tlslegacy/TlsLegacySocketContext.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -26,17 +27,17 @@ namespace apps::tlslegacy { } void TlsLegacySocketContext::onConnected() { - VLOG(1) << getSocketConnection()->getConnectionName() << ": connected"; + snode::semantic::appLog().trace() << getSocketConnection()->getConnectionName() << ": connected"; if (role == Role::CLIENT) { sendToPeer(TLS_HELLO); - VLOG(1) << getSocketConnection()->getConnectionName() << ": sent TLS greeting"; + snode::semantic::appLog().trace() << getSocketConnection()->getConnectionName() << ": sent TLS greeting"; } } void TlsLegacySocketContext::onDisconnected() { legacyRetryTimer.cancel(); - VLOG(1) << getSocketConnection()->getConnectionName() << ": disconnected"; + snode::semantic::appLog().trace() << getSocketConnection()->getConnectionName() << ": disconnected"; } bool TlsLegacySocketContext::onSignal([[maybe_unused]] int signum) { @@ -54,7 +55,7 @@ namespace apps::tlslegacy { } sendToPeer(payload); - VLOG(1) << getSocketConnection()->getConnectionName() << ": trying post-TLS legacy payload: " << payload; + snode::semantic::appLog().trace() << getSocketConnection()->getConnectionName() << ": trying post-TLS legacy payload: " << payload; }, utils::Timeval(0.5)); } @@ -62,14 +63,14 @@ namespace apps::tlslegacy { void TlsLegacySocketContext::onClientLine(const std::string& line) { if (line == TLS_ACK && !tlsReplySeen) { tlsReplySeen = true; - VLOG(1) << getSocketConnection()->getConnectionName() << ": got TLS ack, initiating TLS shutdown handshake (close_notify) " + snode::semantic::appLog().trace() << getSocketConnection()->getConnectionName() << ": got TLS ack, initiating TLS shutdown handshake (close_notify) " << line; shutdownWrite(); startLegacyRetryTimer(LEGACY_HELLO); } else if (line == LEGACY_ACK && !legacyReplySeen) { legacyReplySeen = true; legacyRetryTimer.cancel(); - VLOG(1) << getSocketConnection()->getConnectionName() << ": got LEGACY ack -> post-TLS plaintext path works " << line; + snode::semantic::appLog().trace() << getSocketConnection()->getConnectionName() << ": got LEGACY ack -> post-TLS plaintext path works " << line; shutdownWrite(); } } @@ -78,12 +79,12 @@ namespace apps::tlslegacy { if (line == TLS_HELLO && !tlsReplySeen) { tlsReplySeen = true; sendToPeer(TLS_ACK); - VLOG(1) << getSocketConnection()->getConnectionName() << ": TLS phase complete, waiting for peer close_notify " << line; + snode::semantic::appLog().trace() << getSocketConnection()->getConnectionName() << ": TLS phase complete, waiting for peer close_notify " << line; } else if (line == LEGACY_HELLO && !legacyPayloadSeen) { legacyPayloadSeen = true; legacyRetryTimer.cancel(); sendToPeer(LEGACY_ACK); - VLOG(1) << getSocketConnection()->getConnectionName() << ": received LEGACY payload after TLS shutdown " << line; + snode::semantic::appLog().trace() << getSocketConnection()->getConnectionName() << ": received LEGACY payload after TLS shutdown " << line; shutdownWrite(); } } diff --git a/src/apps/tlslegacy/tlslegacyclient.cpp b/src/apps/tlslegacy/tlslegacyclient.cpp index df855e264e..3c434d2a52 100644 --- a/src/apps/tlslegacy/tlslegacyclient.cpp +++ b/src/apps/tlslegacy/tlslegacyclient.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -27,9 +28,9 @@ int main(int argc, char* argv[]) { client.connect([instanceName = client.getConfig()->getInstanceName()](const SocketClient::SocketAddress& socketAddress, const core::socket::State& state) { if (state == core::socket::State::OK) { - VLOG(1) << instanceName << ": connected to " << socketAddress.toString(); + snode::semantic::appLog().trace() << instanceName << ": connected to " << socketAddress.toString(); } else if (state == core::socket::State::ERROR) { - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); } }); diff --git a/src/apps/tlslegacy/tlslegacyserver.cpp b/src/apps/tlslegacy/tlslegacyserver.cpp index f753401120..77f8decfa1 100644 --- a/src/apps/tlslegacy/tlslegacyserver.cpp +++ b/src/apps/tlslegacy/tlslegacyserver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -27,9 +28,9 @@ int main(int argc, char* argv[]) { server.listen([instanceName = server.getConfig()->getInstanceName()](const SocketServer::SocketAddress& socketAddress, const core::socket::State& state) { if (state == core::socket::State::OK) { - VLOG(1) << instanceName << ": listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << instanceName << ": listening on " << socketAddress.toString(); } else if (state == core::socket::State::ERROR) { - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); } }); diff --git a/src/apps/warema-jalousien.cpp b/src/apps/warema-jalousien.cpp index ade4d51fe5..588994c021 100644 --- a/src/apps/warema-jalousien.cpp +++ b/src/apps/warema-jalousien.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -71,8 +72,8 @@ int main(int argc, char* argv[]) { // tls::WebApp wa; webApp.get("/jalousien/:id", [] APPLICATION(req, res) { - VLOG(1) << "Param: " << req->param("id"); - VLOG(1) << "Qurey: " << req->query("action"); + snode::semantic::appLog().trace() << "Param: " << req->param("id"); + snode::semantic::appLog().trace() << "Qurey: " << req->query("action"); std::string arguments = "aircontrol -t " + jalousien[req->param("id")] + "_" + actions[req->query("action")]; @@ -103,16 +104,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(ERROR) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(FATAL) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/websocket/echoclient.cpp b/src/apps/websocket/echoclient.cpp index 5711d96d13..3a18760595 100644 --- a/src/apps/websocket/echoclient.cpp +++ b/src/apps/websocket/echoclient.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -64,7 +65,7 @@ int main(int argc, char* argv[]) { [](const std::shared_ptr& req) { const std::string connectionName = req->getSocketContext()->getSocketConnection()->getConnectionName(); - VLOG(1) << connectionName << ": OnRequestBegin"; + snode::semantic::appLog().trace() << connectionName << ": OnRequestBegin"; req->set("Sec-WebSocket-Protocol", "subprotocol, echo"); @@ -72,40 +73,40 @@ int main(int argc, char* argv[]) { "/ws", "websocket", [connectionName](bool success) { - VLOG(1) << connectionName << ": HTTP Upgrade (http -> websocket) start " << (success ? "success" : "failed"); + snode::semantic::appLog().trace() << connectionName << ": HTTP Upgrade (http -> websocket) start " << (success ? "success" : "failed"); }, [connectionName]([[maybe_unused]] const std::shared_ptr& req, const std::shared_ptr& res, [[maybe_unused]] bool success) { - VLOG(1) << connectionName << ": Upgrade success:"; + snode::semantic::appLog().trace() << connectionName << ": Upgrade success:"; - VLOG(1) << connectionName << ": Requested: " << req->header("upgrade"); - VLOG(1) << connectionName << ": Selected: " << res->get("upgrade"); + snode::semantic::appLog().trace() << connectionName << ": Requested: " << req->header("upgrade"); + snode::semantic::appLog().trace() << connectionName << ": Selected: " << res->get("upgrade"); }, [connectionName](const std::shared_ptr&, const std::string& message) { - VLOG(1) << connectionName << ": Request parse error: " << message; + snode::semantic::appLog().trace() << connectionName << ": Request parse error: " << message; }); }, []([[maybe_unused]] const std::shared_ptr& req) { const std::string connectionName = req->getConnectionName(); - VLOG(1) << connectionName << ": OnRequestEnd"; + snode::semantic::appLog().trace() << connectionName << ": OnRequestEnd"; }); legacyClient.connect([instanceName = legacyClient.getConfig()->getInstanceName()](const LegacySocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << " connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << " connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << " disabled"; + snode::semantic::appLog().trace() << instanceName << " disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); // Connection:keep-alive\r\n\r\n" @@ -121,7 +122,7 @@ int main(int argc, char* argv[]) { [](const std::shared_ptr& req) { const std::string connectionName = req->getSocketContext()->getSocketConnection()->getConnectionName(); - VLOG(1) << connectionName << ": OnRequestBegin"; + snode::semantic::appLog().trace() << connectionName << ": OnRequestBegin"; req->set("Sec-WebSocket-Protocol", "subprotocol, echo"); @@ -129,36 +130,36 @@ int main(int argc, char* argv[]) { "/ws", "websocket", [connectionName](bool success) { - VLOG(1) << connectionName << ": HTTP Upgrade (http -> websocket) start " << (success ? "success" : "failed"); + snode::semantic::appLog().trace() << connectionName << ": HTTP Upgrade (http -> websocket) start " << (success ? "success" : "failed"); }, [connectionName]([[maybe_unused]] const std::shared_ptr& req, [[maybe_unused]] const std::shared_ptr& res, [[maybe_unused]] bool success) { }, [connectionName](const std::shared_ptr&, const std::string& message) { - VLOG(1) << connectionName << ": Request parse error: " << message; + snode::semantic::appLog().trace() << connectionName << ": Request parse error: " << message; }); }, []([[maybe_unused]] const std::shared_ptr& req) { const std::string connectionName = req->getConnectionName(); - VLOG(1) << connectionName << ": OnRequestEnd"; + snode::semantic::appLog().trace() << connectionName << ": OnRequestEnd"; }); tlsClient.connect([instanceName = tlsClient.getConfig()->getInstanceName()](const TLSSocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << " connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << " connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << " disabled"; + snode::semantic::appLog().trace() << instanceName << " disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); // Connection:keep-alive\r\n\r\n" diff --git a/src/apps/websocket/echoserver.cpp b/src/apps/websocket/echoserver.cpp index 24316cf470..1f40c4928c 100644 --- a/src/apps/websocket/echoserver.cpp +++ b/src/apps/websocket/echoserver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -72,13 +73,13 @@ int main(int argc, char* argv[]) { res->upgrade(req, [req, res, connectionName](const std::string& name) { if (!name.empty()) { - VLOG(1) << connectionName << ": Successful upgrade:"; - VLOG(1) << connectionName << ": Requested: " << req->get("upgrade"); - VLOG(1) << connectionName << ": Selected: " << name; + snode::semantic::appLog().trace() << connectionName << ": Successful upgrade:"; + snode::semantic::appLog().trace() << connectionName << ": Requested: " << req->get("upgrade"); + snode::semantic::appLog().trace() << connectionName << ": Selected: " << name; res->end(); } else { - VLOG(1) << connectionName << ": Can not upgrade to any of '" << req->get("upgrade") << "'"; + snode::semantic::appLog().trace() << connectionName << ": Can not upgrade to any of '" << req->get("upgrade") << "'"; res->sendStatus(404); } @@ -86,18 +87,18 @@ int main(int argc, char* argv[]) { }); legacyApp.get("/", [] APPLICATION(req, res) { - VLOG(1) << "HTTP GET on " + snode::semantic::appLog().trace() << "HTTP GET on " << "/"; if (req->url == "/" || req->url == "/index.html") { req->url = "/wstest.html"; } - VLOG(1) << CMAKE_CURRENT_SOURCE_DIR "/html" + req->url; + snode::semantic::appLog().trace() << CMAKE_CURRENT_SOURCE_DIR "/html" + req->url; res->sendFile(CMAKE_CURRENT_SOURCE_DIR "/html" + req->url, [req, res](int errnum) { if (errnum == 0) { - VLOG(1) << req->url; + snode::semantic::appLog().trace() << req->url; } else { - VLOG(1) << "HTTP response send file failed: " << std::strerror(errnum); + snode::semantic::appLog().trace() << "HTTP response send file failed: " << std::strerror(errnum); res->sendStatus(404); } }); @@ -108,26 +109,26 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << " disabled"; + snode::semantic::appLog().trace() << instanceName << " disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }) .getFlowController(); - VLOG(1) << "Legacy Routes:"; + snode::semantic::appLog().trace() << "Legacy Routes:"; for (std::string& route : legacyApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } { @@ -145,13 +146,13 @@ int main(int argc, char* argv[]) { res->upgrade(req, [req, res, connectionName](const std::string& name) { if (!name.empty()) { - VLOG(1) << connectionName << ": Upgrade success:"; - VLOG(1) << connectionName << ": Requested: " << req->get("upgrade"); - VLOG(1) << connectionName << ": Selected: " << name; + snode::semantic::appLog().trace() << connectionName << ": Upgrade success:"; + snode::semantic::appLog().trace() << connectionName << ": Requested: " << req->get("upgrade"); + snode::semantic::appLog().trace() << connectionName << ": Selected: " << name; res->end(); } else { - VLOG(1) << connectionName << ": Can not upgrade to any of '" << req->get("upgrade") << "'"; + snode::semantic::appLog().trace() << connectionName << ": Can not upgrade to any of '" << req->get("upgrade") << "'"; res->sendStatus(404); } @@ -163,12 +164,12 @@ int main(int argc, char* argv[]) { req->url = "/wstest.html"; } - VLOG(1) << CMAKE_CURRENT_SOURCE_DIR "/html" + req->url; + snode::semantic::appLog().trace() << CMAKE_CURRENT_SOURCE_DIR "/html" + req->url; res->sendFile(CMAKE_CURRENT_SOURCE_DIR "/html" + req->url, [req, res](int errnum) { if (errnum == 0) { - VLOG(1) << req->url; + snode::semantic::appLog().trace() << req->url; } else { - VLOG(1) << "HTTP response send file failed: " << std::strerror(errnum); + snode::semantic::appLog().trace() << "HTTP response send file failed: " << std::strerror(errnum); res->sendStatus(404); } }); @@ -179,26 +180,26 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << " disabled"; + snode::semantic::appLog().trace() << instanceName << " disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }) .getFlowController(); - VLOG(1) << "Tls Routes:"; + snode::semantic::appLog().trace() << "Tls Routes:"; for (std::string& route : legacyApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } } diff --git a/src/apps/websocket/subprotocol/client/echo/Echo.cpp b/src/apps/websocket/subprotocol/client/echo/Echo.cpp index 8eac73f097..665aecde0c 100644 --- a/src/apps/websocket/subprotocol/client/echo/Echo.cpp +++ b/src/apps/websocket/subprotocol/client/echo/Echo.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -60,24 +61,24 @@ namespace apps::websocket::subprotocol::echo::client { } void Echo::onConnected() { - VLOG(1) << "Echo connected"; + snode::semantic::appLog().trace() << "Echo connected"; sendMessage("Welcome to SimpleChat"); sendMessage("====================="); } void Echo::onMessageStart(int opCode) { - VLOG(2) << "Message Start - OpCode: " << opCode; + snode::semantic::appLog().trace() << "Message Start - OpCode: " << opCode; } void Echo::onMessageData(const char* chunk, std::size_t chunkLen) { data += std::string(chunk, chunkLen); - VLOG(2) << "Message Fragment: " << std::string(chunk, chunkLen); + snode::semantic::appLog().trace() << "Message Fragment: " << std::string(chunk, chunkLen); } void Echo::onMessageEnd() { - VLOG(1) << "Message Data: " << data; + snode::semantic::appLog().trace() << "Message Data: " << data; // To do ping-pong // sendMessage(data); @@ -86,15 +87,15 @@ namespace apps::websocket::subprotocol::echo::client { } void Echo::onMessageError(uint16_t errnum) { - VLOG(1) << "Message error: " << errnum; + snode::semantic::appLog().trace() << "Message error: " << errnum; } void Echo::onDisconnected() { - VLOG(1) << "Echo disconnected:"; + snode::semantic::appLog().trace() << "Echo disconnected:"; } bool Echo::onSignal(int sig) { - VLOG(1) << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig + snode::semantic::appLog().trace() << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig << ")"; sendClose(); diff --git a/src/apps/websocket/subprotocol/server/echo/Echo.cpp b/src/apps/websocket/subprotocol/server/echo/Echo.cpp index 26d976417e..e8f6629161 100644 --- a/src/apps/websocket/subprotocol/server/echo/Echo.cpp +++ b/src/apps/websocket/subprotocol/server/echo/Echo.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -60,21 +61,21 @@ namespace apps::websocket::subprotocol::echo::server { } void Echo::onConnected() { - VLOG(1) << "Echo connected"; + snode::semantic::appLog().trace() << "Echo connected"; } void Echo::onMessageStart(int opCode) { - VLOG(2) << "Message Start - OpCode: " << opCode; + snode::semantic::appLog().trace() << "Message Start - OpCode: " << opCode; } void Echo::onMessageData(const char* chunk, std::size_t chunkLen) { data += std::string(chunk, chunkLen); - VLOG(2) << "Message Fragment: " << std::string(chunk, chunkLen); + snode::semantic::appLog().trace() << "Message Fragment: " << std::string(chunk, chunkLen); } void Echo::onMessageEnd() { - VLOG(1) << "Message Data: " << data; + snode::semantic::appLog().trace() << "Message Data: " << data; // Alternative // forEachClient([&data = this->data](SubProtocol* client) { @@ -87,15 +88,15 @@ namespace apps::websocket::subprotocol::echo::server { } void Echo::onMessageError(uint16_t errnum) { - VLOG(1) << "Message error: " << errnum; + snode::semantic::appLog().trace() << "Message error: " << errnum; } void Echo::onDisconnected() { - VLOG(1) << "Echo disconnected:"; + snode::semantic::appLog().trace() << "Echo disconnected:"; } bool Echo::onSignal(int sig) { - VLOG(1) << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig + snode::semantic::appLog().trace() << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig << ")"; sendClose(); diff --git a/src/core/DescriptorEventReceiver.cpp b/src/core/DescriptorEventReceiver.cpp index e589cab0e3..83753dc2a1 100644 --- a/src/core/DescriptorEventReceiver.cpp +++ b/src/core/DescriptorEventReceiver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -99,9 +100,9 @@ namespace core { enabled = true; descriptorEventPublisher.enable(this); - LOG(TRACE) << getName() << ": Enabled"; + snode::semantic::appLog().trace() << getName() << ": Enabled"; } else { - LOG(WARNING) << getName() << ": Double enable"; + snode::semantic::appLog().warn() << getName() << ": Double enable"; } return enabled; @@ -111,9 +112,9 @@ namespace core { if (enabled) { enabled = false; descriptorEventPublisher.disable(this); - LOG(TRACE) << getName() << ": Disabled"; + snode::semantic::appLog().trace() << getName() << ": Disabled"; } else { - LOG(WARNING) << getName() << ": Double disable"; + snode::semantic::appLog().warn() << getName() << ": Double disable"; } } @@ -123,10 +124,10 @@ namespace core { suspended = true; descriptorEventPublisher.suspend(this); } else { - LOG(WARNING) << getName() << ": Double suspend"; + snode::semantic::appLog().warn() << getName() << ": Double suspend"; } } else { - LOG(WARNING) << getName() << ": Suspend while not enabled"; + snode::semantic::appLog().warn() << getName() << ": Suspend while not enabled"; } } @@ -137,10 +138,10 @@ namespace core { lastTriggered = utils::Timeval::currentTime(); descriptorEventPublisher.resume(this); } else { - LOG(WARNING) << getName() << ": Double resume"; + snode::semantic::appLog().warn() << getName() << ": Double resume"; } } else { - LOG(WARNING) << getName() << ": Resume while not enabled"; + snode::semantic::appLog().warn() << getName() << ": Resume while not enabled"; } } diff --git a/src/core/DynamicLoader.cpp b/src/core/DynamicLoader.cpp index 070d7f78ff..380c3b57a7 100644 --- a/src/core/DynamicLoader.cpp +++ b/src/core/DynamicLoader.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -84,7 +85,7 @@ namespace core { ++lib.refCount; lib.closePending = false; - LOG(TRACE) << "DynLoader dlOpen: " << lib.fileName << ": already open (refCount=" << lib.refCount << ")"; + snode::semantic::appLog().trace() << "DynLoader dlOpen: " << lib.fileName << ": already open (refCount=" << lib.refCount << ")"; handle = lib.handle; } else { // Clear possible stale error @@ -102,9 +103,9 @@ namespace core { dlOpenedLibraries.emplace(canonicalFile, lib); dlOpenedLibrariesByHandle.emplace(handle, canonicalFile); - LOG(TRACE) << "DynLoader dlOpen: " << libFile << ": success"; + snode::semantic::appLog().trace() << "DynLoader dlOpen: " << libFile << ": success"; } else { - LOG(TRACE) << "DynLoader dlOpen: " << libFile << ": " << DynamicLoader::dlError(); + snode::semantic::appLog().trace() << "DynLoader dlOpen: " << libFile << ": " << DynamicLoader::dlError(); } } @@ -113,15 +114,15 @@ namespace core { void DynamicLoader::dlCloseDelayed(void* handle) { if (handle == nullptr) { - LOG(TRACE) << "DynLoader dlCloseDelayed: handle is nullptr"; + snode::semantic::appLog().trace() << "DynLoader dlCloseDelayed: handle is nullptr"; } else { auto itHandle = dlOpenedLibrariesByHandle.find(handle); if (itHandle == dlOpenedLibrariesByHandle.end()) { - LOG(TRACE) << "DynLoader dlCloseDelayed: " << handle << ": not opened using dlOpen"; + snode::semantic::appLog().trace() << "DynLoader dlCloseDelayed: " << handle << ": not opened using dlOpen"; } else { auto itLib = dlOpenedLibraries.find(itHandle->second); if (itLib == dlOpenedLibraries.end()) { - LOG(TRACE) << "DynLoader: dlCloseDelayed: internal error: handle known but library record missing"; + snode::semantic::appLog().trace() << "DynLoader: dlCloseDelayed: internal error: handle known but library record missing"; } else { Library& lib = itLib->second; @@ -132,9 +133,9 @@ namespace core { if (lib.refCount == 0) { lib.closePending = true; closeQueue.push_back(lib.canonicalFileName); - LOG(TRACE) << "DynLoader dlCloseDelayed: " << lib.fileName; + snode::semantic::appLog().trace() << "DynLoader dlCloseDelayed: " << lib.fileName; } else { - LOG(TRACE) << "DynLoader dlCloseDelayed: " << lib.fileName << ": still referenced (refCount=" << lib.refCount + snode::semantic::appLog().trace() << "DynLoader dlCloseDelayed: " << lib.fileName << ": still referenced (refCount=" << lib.refCount << ")"; } } @@ -146,15 +147,15 @@ namespace core { int ret = 0; if (handle == nullptr) { - LOG(TRACE) << "DynLoader dlClose: handle is nullptr"; + snode::semantic::appLog().trace() << "DynLoader dlClose: handle is nullptr"; } else { auto itHandle = dlOpenedLibrariesByHandle.find(handle); if (itHandle == dlOpenedLibrariesByHandle.end()) { - LOG(TRACE) << "DynLoader dlClose: " << handle << ": not opened using dlOpen"; + snode::semantic::appLog().trace() << "DynLoader dlClose: " << handle << ": not opened using dlOpen"; } else { auto itLib = dlOpenedLibraries.find(itHandle->second); if (itLib == dlOpenedLibraries.end()) { - LOG(TRACE) << "DynLoader dlClose: internal error: handle known but library record missing"; + snode::semantic::appLog().trace() << "DynLoader dlClose: internal error: handle known but library record missing"; } else { Library& lib = itLib->second; @@ -163,7 +164,7 @@ namespace core { } if (lib.refCount != 0) { - LOG(TRACE) << "DynLoader dlClose: " << lib.fileName << ": still referenced (refCount=" << lib.refCount << ")"; + snode::semantic::appLog().trace() << "DynLoader dlClose: " << lib.fileName << ": still referenced (refCount=" << lib.refCount << ")"; } else { lib.closePending = false; ret = dlClose(lib); @@ -199,9 +200,9 @@ namespace core { ret = realExecDlClose(library); if (ret != 0) { - LOG(TRACE) << "DynLoader dlClose: " << DynamicLoader::dlError(); + snode::semantic::appLog().trace() << "DynLoader dlClose: " << DynamicLoader::dlError(); } else { - LOG(TRACE) << "DynLoader dlClose: " << library.fileName << ": success"; + snode::semantic::appLog().trace() << "DynLoader dlClose: " << library.fileName << ": success"; } return ret; diff --git a/src/core/EventLoop.cpp b/src/core/EventLoop.cpp index 3d8eb6756a..53a9f22a83 100644 --- a/src/core/EventLoop.cpp +++ b/src/core/EventLoop.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -119,7 +120,7 @@ namespace core { if (utils::Config::init(argc, argv)) { eventLoopState = State::INITIALIZED; - LOG(TRACE) << "SNode.C: Starting ... HELLO"; + snode::semantic::appLog().trace() << "SNode.C: Starting ... HELLO"; } sigaction(SIGPIPE, &oldPipeAct, nullptr); @@ -173,7 +174,7 @@ namespace core { EventLoop::instance().eventMultiplexer.clearEventQueue(); free(); - PLOG(FATAL) << "Core: not initialized: No events will be processed\nCall SNodeC::init(argc, argv) before SNodeC::tick()."; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Critical, errno) << "Core: not initialized: No events will be processed\nCall SNodeC::init(argc, argv) before SNodeC::tick()."; } return tickStatus; @@ -207,7 +208,7 @@ namespace core { eventLoopState = State::RUNNING; core::TickStatus tickStatus = TickStatus::SUCCESS; - LOG(TRACE) << "Core::EventLoop: started"; + snode::semantic::appLog().trace() << "Core::EventLoop: started"; do { tickStatus = EventLoop::instance()._tick(timeOut); @@ -215,16 +216,16 @@ namespace core { switch (tickStatus) { case TickStatus::SUCCESS: - LOG(TRACE) << "Core::EventLoop: Stopped"; + snode::semantic::appLog().trace() << "Core::EventLoop: Stopped"; break; case TickStatus::NOOBSERVER: - LOG(TRACE) << "Core::EventLoop: No Observer"; + snode::semantic::appLog().trace() << "Core::EventLoop: No Observer"; break; case TickStatus::INTERRUPTED: - LOG(TRACE) << "Core::EventLoop: Interrupted"; + snode::semantic::appLog().trace() << "Core::EventLoop: Interrupted"; break; case TickStatus::TRACE: - PLOG(FATAL) << "Core::EventLoop: _tick()"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Critical, errno) << "Core::EventLoop: _tick()"; break; } } else { @@ -258,7 +259,7 @@ namespace core { } if (stopsig != 0) { - LOG(TRACE) << "Core: Sending signal " << signal << " to all DescriptorEventReceivers"; + snode::semantic::appLog().trace() << "Core: Sending signal " << signal << " to all DescriptorEventReceivers"; EventLoop::instance().eventMultiplexer.signal(stopsig); } @@ -267,7 +268,7 @@ namespace core { utils::Timeval timeout = 2; - LOG(TRACE) << "Core: Terminate all stalled DescriptorEventReceivers"; + snode::semantic::appLog().trace() << "Core: Terminate all stalled DescriptorEventReceivers"; EventLoop::instance().eventMultiplexer.terminate(); @@ -284,17 +285,17 @@ namespace core { timeout -= seconds.count(); } while (timeout > 0 && (tickStatus == TickStatus::SUCCESS)); - LOG(TRACE) << "Core: Shutdown config system"; + snode::semantic::appLog().trace() << "Core: Shutdown config system"; utils::Config::terminate(); - LOG(TRACE) << "Core: All resources released"; + snode::semantic::appLog().trace() << "Core: All resources released"; - LOG(TRACE) << "SNode.C: Ended ... BYE"; + snode::semantic::appLog().trace() << "SNode.C: Ended ... BYE"; } void EventLoop::stoponsig(int sig) { - LOG(TRACE) << "Core: Received signal '" << utils::system::strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " + snode::semantic::appLog().trace() << "Core: Received signal '" << utils::system::strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig << ")"; stopsig = sig; stop(); diff --git a/src/core/TimerEventReceiver.cpp b/src/core/TimerEventReceiver.cpp index 909515f9fa..91d480ca5a 100644 --- a/src/core/TimerEventReceiver.cpp +++ b/src/core/TimerEventReceiver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -85,7 +86,7 @@ namespace core { if (core::eventLoopState() != core::State::STOPPING) { timerEventPublisher.insert(this); } else { - LOG(WARNING) << "TimerEventReceiver - Enable after signal: Not enabled"; + snode::semantic::appLog().warn() << "TimerEventReceiver - Enable after signal: Not enabled"; delete this; } } @@ -101,7 +102,7 @@ namespace core { } void TimerEventReceiver::onEvent(const utils::Timeval& currentTime) { - LOG(TRACE) << "TimerEventReceiver: Dispatch delta = " << (currentTime - getTimeoutAbsolut()).getMsd() << " ms"; + snode::semantic::appLog().trace() << "TimerEventReceiver: Dispatch delta = " << (currentTime - getTimeoutAbsolut()).getMsd() << " ms"; dispatchEvent(); } diff --git a/src/core/multiplexer/epoll/EventMultiplexer.cpp b/src/core/multiplexer/epoll/EventMultiplexer.cpp index afb82692d5..dfadc9eec3 100644 --- a/src/core/multiplexer/epoll/EventMultiplexer.cpp +++ b/src/core/multiplexer/epoll/EventMultiplexer.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -87,7 +88,7 @@ namespace core::multiplexer::epoll { event.data.ptr = descriptorEventPublishers[core::EventMultiplexer::DISP_TYPE::EX]; core::system::epoll_ctl(epfd, EPOLL_CTL_ADD, epfds[core::EventMultiplexer::DISP_TYPE::EX], &event); - LOG(DEBUG) << "Core::multiplexer: epoll"; + snode::semantic::appLog().debug() << "Core::multiplexer: epoll"; } int EventMultiplexer::monitorDescriptors(utils::Timeval& tickTimeout, const sigset_t& sigMask) { diff --git a/src/core/multiplexer/poll/EventMultiplexer.cpp b/src/core/multiplexer/poll/EventMultiplexer.cpp index fced67af61..00059f248e 100644 --- a/src/core/multiplexer/poll/EventMultiplexer.cpp +++ b/src/core/multiplexer/poll/EventMultiplexer.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -163,7 +164,7 @@ namespace core::multiplexer::poll { pollFdsManager, POLLPRI, POLLPRI)) { - LOG(DEBUG) << "Core::multiplexer: poll"; + snode::semantic::appLog().debug() << "Core::multiplexer: poll"; } int EventMultiplexer::monitorDescriptors(utils::Timeval& tickTimeOut, const sigset_t& sigMask) { diff --git a/src/core/multiplexer/select/EventMultiplexer.cpp b/src/core/multiplexer/select/EventMultiplexer.cpp index 02b8115f3e..601faaa41d 100644 --- a/src/core/multiplexer/select/EventMultiplexer.cpp +++ b/src/core/multiplexer/select/EventMultiplexer.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -68,7 +69,7 @@ namespace core::multiplexer::select { fdSets[core::EventMultiplexer::DISP_TYPE::WR]), new core::multiplexer::select::DescriptorEventPublisher("EXCEPT", // fdSets[core::EventMultiplexer::DISP_TYPE::EX])) { - LOG(DEBUG) << "Core::multiplexer: select"; + snode::semantic::appLog().debug() << "Core::multiplexer: select"; } int EventMultiplexer::monitorDescriptors(utils::Timeval& tickTimeOut, const sigset_t& sigMask) { diff --git a/src/core/socket/stream/SocketAcceptor.hpp b/src/core/socket/stream/SocketAcceptor.hpp index 6b67c72190..834071d5d3 100644 --- a/src/core/socket/stream/SocketAcceptor.hpp +++ b/src/core/socket/stream/SocketAcceptor.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -101,12 +102,12 @@ namespace core::socket::stream { try { core::socket::State state = core::socket::STATE_OK; - LOG(DEBUG) << config->getInstanceName() << " Listen: starting"; + snode::semantic::appLog().debug() << config->getInstanceName() << " Listen: starting"; bindAddress = config->Local::getSocketAddress(); if (physicalServerSocket.open(config->getSocketOptions(), PhysicalServerSocket::Flags::NONBLOCK) < 0) { - PLOG(ERROR) << config->getInstanceName() << " open " << bindAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << config->getInstanceName() << " open " << bindAddress.toString(); switch (errno) { case EMFILE: @@ -120,10 +121,10 @@ namespace core::socket::stream { break; } } else { - LOG(DEBUG) << config->getInstanceName() << " open " << bindAddress.toString() << ": success"; + snode::semantic::appLog().debug() << config->getInstanceName() << " open " << bindAddress.toString() << ": success"; if (physicalServerSocket.bind(bindAddress) < 0) { - PLOG(ERROR) << config->getInstanceName() << " bind " << bindAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << config->getInstanceName() << " bind " << bindAddress.toString(); switch (errno) { case EADDRINUSE: @@ -136,10 +137,10 @@ namespace core::socket::stream { break; } } else { - LOG(DEBUG) << config->getInstanceName() << " bind " << bindAddress.toString() << ": success"; + snode::semantic::appLog().debug() << config->getInstanceName() << " bind " << bindAddress.toString() << ": success"; if (physicalServerSocket.listen(config->getBacklog()) < 0) { - PLOG(ERROR) << config->getInstanceName() << " listen " << bindAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << config->getInstanceName() << " listen " << bindAddress.toString(); switch (errno) { case EADDRINUSE: @@ -150,12 +151,12 @@ namespace core::socket::stream { break; } } else { - LOG(DEBUG) << config->getInstanceName() << " listen " << bindAddress.toString() << ": success"; + snode::semantic::appLog().debug() << config->getInstanceName() << " listen " << bindAddress.toString() << ": success"; if (enable(physicalServerSocket.getFd())) { - LOG(DEBUG) << config->getInstanceName() << " enable " << bindAddress.toString() << ": success"; + snode::semantic::appLog().debug() << config->getInstanceName() << " enable " << bindAddress.toString() << ": success"; } else { - LOG(ERROR) << config->getInstanceName() << " enable " << bindAddress.toString() + snode::semantic::appLog().error() << config->getInstanceName() << " enable " << bindAddress.toString() << ": failed. No valid descriptor created"; state = core::socket::STATE(core::socket::STATE_FATAL, ECANCELED, "SocketAcceptor not enabled"); @@ -168,7 +169,7 @@ namespace core::socket::stream { if (bindAddress.useNext()) { onStatus(currentLocalAddress, (state | core::socket::State::NO_RETRY)); - LOG(INFO) << config->getInstanceName() + snode::semantic::appLog().info() << config->getInstanceName() << ": Using next SocketAddress: " << config->Local::getSocketAddress().toString(); useNextSocketAddress(); @@ -179,12 +180,12 @@ namespace core::socket::stream { core::socket::State state = core::socket::STATE(badSocketAddress.getState(), badSocketAddress.getErrnum(), badSocketAddress.what()); - LOG(ERROR) << state.what(); + snode::semantic::appLog().error() << state.what(); onStatus({}, state); } } else { - LOG(DEBUG) << config->getInstanceName() << ": disabled"; + snode::semantic::appLog().debug() << config->getInstanceName() << ": disabled"; onStatus({}, core::socket::STATE_DISABLED); } @@ -211,14 +212,14 @@ namespace core::socket::stream { if (connectedPhysicalSocket.isValid()) { SocketConnection* socketConnection = new SocketConnection(std::move(connectedPhysicalSocket), onDisconnect, config); - LOG(DEBUG) << config->getInstanceName() << " accept " << bindAddress.toString() << ": success"; - LOG(DEBUG) << " " << socketConnection->getRemoteAddress().toString() << " -> " + snode::semantic::appLog().debug() << config->getInstanceName() << " accept " << bindAddress.toString() << ": success"; + snode::semantic::appLog().debug() << " " << socketConnection->getRemoteAddress().toString() << " -> " << socketConnection->getLocalAddress().toString(); onConnect(socketConnection); onConnected(socketConnection); } else if (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK) { - PLOG(WARNING) << config->getInstanceName() << " accept " << bindAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Warning, errno) << config->getInstanceName() << " accept " << bindAddress.toString(); } } while (--acceptsPerTick > 0); } diff --git a/src/core/socket/stream/SocketClient.h b/src/core/socket/stream/SocketClient.h index 3e9bec755a..127d3895bd 100644 --- a/src/core/socket/stream/SocketClient.h +++ b/src/core/socket/stream/SocketClient.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -126,40 +127,40 @@ namespace core::socket::stream { this->config, std::make_shared(std::forward(args)...), [onConnect](SocketConnection* socketConnection) { // onConnect - LOG(DEBUG) << socketConnection->getConnectionName() << ": OnConnect"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnConnect"; - LOG(DEBUG) << " Local: " << socketConnection->getLocalAddress().toString(); - LOG(DEBUG) << " Peer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << " Local: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(); if (onConnect) { onConnect(socketConnection); } }, [onConnected](SocketConnection* socketConnection) { // onConnected - LOG(DEBUG) << socketConnection->getConnectionName() << ": OnConnected"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnConnected"; - LOG(DEBUG) << " Local: " << socketConnection->getLocalAddress().toString(); - LOG(DEBUG) << " Peer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << " Local: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(); if (onConnected) { onConnected(socketConnection); } }, [onDisconnect](SocketConnection* socketConnection) { // onDisconnect - LOG(DEBUG) << socketConnection->getConnectionName() << ": OnDisconnect"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnDisconnect"; - LOG(DEBUG) << " Local: " << socketConnection->getLocalAddress().toString(); - LOG(DEBUG) << " Peer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << " Local: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(); - LOG(DEBUG) << " Online Since: " << socketConnection->getOnlineSince(); - LOG(DEBUG) << " Online Duration: " << socketConnection->getOnlineDuration(); + snode::semantic::appLog().debug() << " Online Since: " << socketConnection->getOnlineSince(); + snode::semantic::appLog().debug() << " Online Duration: " << socketConnection->getOnlineDuration(); - LOG(DEBUG) << " Total Queued: " << socketConnection->getTotalQueued(); - LOG(DEBUG) << " Total Sent: " << socketConnection->getTotalSent(); - LOG(DEBUG) << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent(); - LOG(DEBUG) << " Total Read: " << socketConnection->getTotalRead(); - LOG(DEBUG) << " Total Processed: " << socketConnection->getTotalProcessed(); - LOG(DEBUG) << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed(); + snode::semantic::appLog().debug() << " Total Queued: " << socketConnection->getTotalQueued(); + snode::semantic::appLog().debug() << " Total Sent: " << socketConnection->getTotalSent(); + snode::semantic::appLog().debug() << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent(); + snode::semantic::appLog().debug() << " Total Read: " << socketConnection->getTotalRead(); + snode::semantic::appLog().debug() << " Total Processed: " << socketConnection->getTotalProcessed(); + snode::semantic::appLog().debug() << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed(); if (onDisconnect) { onDisconnect(socketConnection); @@ -189,7 +190,7 @@ namespace core::socket::stream { sharedContext->flowController.startFlow( [config = this->config, sharedContext = this->sharedContext, onStatus, tries, retryTimeoutScale] { if (config->Instance::getParent() != nullptr || !config->Instance::getRequired()) { - LOG(DEBUG) << config->getInstanceName() << ": Initiating connect"; + snode::semantic::appLog().debug() << config->getInstanceName() << ": Initiating connect"; if (core::SNodeC::state() == core::State::RUNNING || core::SNodeC::state() == core::State::INITIALIZED) { new SocketConnector( @@ -203,7 +204,7 @@ namespace core::socket::stream { core::eventLoopState() == core::State::RUNNING) { double relativeReconnectTimeout = config->getReconnectTime(); - LOG(INFO) + snode::semantic::appLog().info() << config->getInstanceName() << ": Reconnect in " << relativeReconnectTimeout << " seconds"; sharedContext->flowController.armReconnectTimer( @@ -215,7 +216,7 @@ namespace core::socket::stream { sharedContext->flowController.reportFlowReconnect(); SocketClient(config, sharedContext).realConnect(onStatus, 0, config->getRetryBase()); } else { - LOG(INFO) << config->getInstanceName() << ": Reconnect disabled during wait"; + snode::semantic::appLog().info() << config->getInstanceName() << ": Reconnect disabled during wait"; } }); } @@ -243,7 +244,7 @@ namespace core::socket::stream { utils::Random::getInRange(-config->getRetryJitter(), config->getRetryJitter()) * relativeRetryTimeout / 100.; - LOG(INFO) + snode::semantic::appLog().info() << config->getInstanceName() << ": Retry connect in " << relativeRetryTimeout << " seconds"; sharedContext->flowController.armRetryTimer( @@ -261,7 +262,7 @@ namespace core::socket::stream { SocketClient(config, sharedContext) .realConnect(onStatus, tries + 1, retryTimeoutScale * config->getRetryBase()); } else { - LOG(INFO) << config->getInstanceName() << ": Retry connect disabled during wait"; + snode::semantic::appLog().info() << config->getInstanceName() << ": Retry connect disabled during wait"; } }); } @@ -269,7 +270,7 @@ namespace core::socket::stream { config); } } else { - LOG(FATAL) << config->getInstanceName() << " required"; + snode::semantic::appLog().critical() << config->getInstanceName() << " required"; } }); diff --git a/src/core/socket/stream/SocketConnection.cpp b/src/core/socket/stream/SocketConnection.cpp index 2951fbedc8..ecafeed568 100644 --- a/src/core/socket/stream/SocketConnection.cpp +++ b/src/core/socket/stream/SocketConnection.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -72,10 +73,10 @@ namespace core::socket::stream { SocketContext* socketContext = socketContextFactory->create(this); if (socketContext != nullptr) { - LOG(DEBUG) << connectionName << ": SocketContext created successful"; + snode::semantic::appLog().debug() << connectionName << ": SocketContext created successful"; setSocketContext(socketContext); } else { - LOG(ERROR) << connectionName << ": SocketContext failed to create"; + snode::semantic::appLog().error() << connectionName << ": SocketContext failed to create"; close(); } } @@ -86,7 +87,7 @@ namespace core::socket::stream { socketContext->attach(); } else { - LOG(DEBUG) << connectionName << " SocketContext: switch"; + snode::semantic::appLog().debug() << connectionName << " SocketContext: switch"; newSocketContext = socketContext; } diff --git a/src/core/socket/stream/SocketConnection.hpp b/src/core/socket/stream/SocketConnection.hpp index a198c6354a..a89276f28f 100644 --- a/src/core/socket/stream/SocketConnection.hpp +++ b/src/core/socket/stream/SocketConnection.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -64,14 +65,14 @@ namespace core::socket::stream { if (physicalSocket.getSockName(localSockAddr, localSockAddrLen) == 0) { try { localPeerAddress = config->Local::getSocketAddress(localSockAddr, localSockAddrLen); - LOG(TRACE) << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) + snode::semantic::appLog().trace() << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) << " PeerAddress (local): " << localPeerAddress.toString(); } catch (const typename SocketAddress::BadSocketAddress& badSocketAddress) { - LOG(WARNING) << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) + snode::semantic::appLog().warn() << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) << " PeerAddress (local): " << badSocketAddress.what(); } } else { - PLOG(WARNING) << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Warning, errno) << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) << " PeerAddress (local) not retrievable"; } @@ -87,14 +88,14 @@ namespace core::socket::stream { if (physicalSocket.getPeerName(remoteSockAddr, remoteSockAddrLen) == 0) { try { remotePeerAddress = config->Remote::getSocketAddress(remoteSockAddr, remoteSockAddrLen); - LOG(TRACE) << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) + snode::semantic::appLog().trace() << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) << " PeerAddress (remote): " << remotePeerAddress.toString(); } catch (const typename SocketAddress::BadSocketAddress& badSocketAddress) { - LOG(WARNING) << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) + snode::semantic::appLog().warn() << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) << " PeerAddress (remote): " << badSocketAddress.what(); } } else { - PLOG(WARNING) << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Warning, errno) << config->getInstanceName() << " [" << physicalSocket.getFd() << "]" << std::setw(25) << " PeerAddress (remote) not retrievble"; } @@ -112,9 +113,9 @@ namespace core::socket::stream { { const utils::PreserveErrno pe(errnum); if (errno == 0) { - LOG(TRACE) << connectionName << " OnReadError: EOF received"; + snode::semantic::appLog().trace() << connectionName << " OnReadError: EOF received"; } else { - PLOG(TRACE) << connectionName << " OnReadError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Trace, errno) << connectionName << " OnReadError"; } } SocketReader::disable(); @@ -129,7 +130,7 @@ namespace core::socket::stream { [this](int errnum) { { const utils::PreserveErrno pe(errnum); - PLOG(TRACE) << connectionName << " OnWriteError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Trace, errno) << connectionName << " OnWriteError"; } SocketWriter::disable(); @@ -201,7 +202,7 @@ namespace core::socket::stream { if (newSocketContext == nullptr) { ret = SocketReader::readFromPeer(chunk, chunkLen); } else { - LOG(TRACE) << connectionName << " ReadFromPeer: New SocketContext != nullptr: SocketContextSwitch still in progress"; + snode::semantic::appLog().trace() << connectionName << " ReadFromPeer: New SocketContext != nullptr: SocketContextSwitch still in progress"; } return ret; @@ -224,21 +225,21 @@ namespace core::socket::stream { template void SocketConnectionT::shutdownRead() { - LOG(TRACE) << connectionName << ": Shutdown (RD)"; + snode::semantic::appLog().trace() << connectionName << ": Shutdown (RD)"; SocketReader::shutdownRead(); if (physicalSocket.shutdown(PhysicalSocket::SHUT::RD) == 0) { - LOG(DEBUG) << connectionName << " Shutdown (RD): success"; + snode::semantic::appLog().debug() << connectionName << " Shutdown (RD): success"; } else { - PLOG(ERROR) << connectionName << " Shutdown (RD)"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << connectionName << " Shutdown (RD)"; } } template void SocketConnectionT::shutdownWrite() { if (!SocketWriter::shutdownInProgress) { - LOG(TRACE) << connectionName << ": Stop writing"; + snode::semantic::appLog().trace() << connectionName << ": Stop writing"; SocketWriter::shutdownWrite([this]() { if (SocketWriter::isEnabled()) { @@ -289,12 +290,12 @@ namespace core::socket::stream { setTimeout(SocketWriter::terminateTimeout); - LOG(TRACE) << connectionName << ": Shutdown (WR)"; + snode::semantic::appLog().trace() << connectionName << ": Shutdown (WR)"; if (physicalSocket.shutdown(PhysicalSocket::SHUT::WR) == 0) { - LOG(DEBUG) << connectionName << " Shutdown (WR): success"; + snode::semantic::appLog().debug() << connectionName << " Shutdown (WR): success"; } else { - PLOG(ERROR) << connectionName << " Shutdown (WR)"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << connectionName << " Shutdown (WR)"; } onShutdown(); @@ -305,7 +306,7 @@ namespace core::socket::stream { std::size_t consumed = socketContext->readFromPeer(); if (available != 0 && consumed == 0) { - LOG(TRACE) << connectionName << ": Data available: " << available << " but nothing read"; + snode::semantic::appLog().trace() << connectionName << ": Data available: " << available << " but nothing read"; close(); @@ -319,7 +320,7 @@ namespace core::socket::stream { socketContext->attach(); - LOG(DEBUG) << connectionName << " SocketConnection: switch completed"; + snode::semantic::appLog().debug() << connectionName << " SocketConnection: switch completed"; } } @@ -343,7 +344,7 @@ namespace core::socket::stream { case SIGABRT: [[fallthrough]]; case SIGHUP: - LOG(DEBUG) << connectionName << ": Shutting down due to signal '" << utils::system::strsignal(signum) << "' (SIG" + snode::semantic::appLog().debug() << connectionName << ": Shutting down due to signal '" << utils::system::strsignal(signum) << "' (SIG" << utils::system::sigabbrev_np(signum) << " [" << signum << "])"; break; case SIGALRM: @@ -355,13 +356,13 @@ namespace core::socket::stream { template void SocketConnectionT::readTimeout() { - LOG(WARNING) << connectionName << ": Read timeout"; + snode::semantic::appLog().warn() << connectionName << ": Read timeout"; close(); } template void SocketConnectionT::writeTimeout() { - LOG(WARNING) << connectionName << ": Write timeout"; + snode::semantic::appLog().warn() << connectionName << ": Write timeout"; close(); } @@ -373,7 +374,7 @@ namespace core::socket::stream { onDisconnect(); - LOG(DEBUG) << connectionName << ": disconnected"; + snode::semantic::appLog().debug() << connectionName << ": disconnected"; delete this; } diff --git a/src/core/socket/stream/SocketConnector.hpp b/src/core/socket/stream/SocketConnector.hpp index 5640b70c48..b87d87975f 100644 --- a/src/core/socket/stream/SocketConnector.hpp +++ b/src/core/socket/stream/SocketConnector.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -101,7 +102,7 @@ namespace core::socket::stream { try { core::socket::State state = core::socket::STATE_OK; - LOG(DEBUG) << config->getInstanceName() << " Connect: starting"; + snode::semantic::appLog().debug() << config->getInstanceName() << " Connect: starting"; SocketAddress bindAddress = config->Local::getSocketAddress(); @@ -109,7 +110,7 @@ namespace core::socket::stream { remoteAddress = config->Remote::getSocketAddress(); if (physicalClientSocket.open(config->getSocketOptions(), PhysicalClientSocket::Flags::NONBLOCK) < 0) { - PLOG(DEBUG) << config->getInstanceName() << " open " << bindAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << config->getInstanceName() << " open " << bindAddress.toString(); switch (errno) { case EMFILE: @@ -125,10 +126,10 @@ namespace core::socket::stream { onStatus(bindAddress, state); } else { - LOG(TRACE) << config->getInstanceName() << " open " << bindAddress.toString() << ": success"; + snode::semantic::appLog().trace() << config->getInstanceName() << " open " << bindAddress.toString() << ": success"; if (physicalClientSocket.bind(bindAddress) < 0) { - PLOG(DEBUG) << config->getInstanceName() << " bind " << bindAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << config->getInstanceName() << " bind " << bindAddress.toString(); switch (errno) { case EADDRINUSE: @@ -141,10 +142,10 @@ namespace core::socket::stream { onStatus(bindAddress, state); } else { - LOG(TRACE) << config->getInstanceName() << " bind " << bindAddress.toString() << ": success"; + snode::semantic::appLog().trace() << config->getInstanceName() << " bind " << bindAddress.toString() << ": success"; if (physicalClientSocket.connect(remoteAddress) < 0 && !PhysicalClientSocket::connectInProgress(errno)) { - PLOG(DEBUG) << config->getInstanceName() << " connect " << remoteAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << config->getInstanceName() << " connect " << remoteAddress.toString(); switch (errno) { case EADDRINUSE: case EADDRNOTAVAIL: @@ -163,21 +164,21 @@ namespace core::socket::stream { if (remoteAddress.useNext()) { onStatus(currentRemoteAddress, state | core::socket::State::NO_RETRY); - LOG(INFO) << config->getInstanceName() << ": Using next SocketAddress: " << remoteAddress.toString(); + snode::semantic::appLog().info() << config->getInstanceName() << ": Using next SocketAddress: " << remoteAddress.toString(); useNextSocketAddress(); } else { onStatus(currentRemoteAddress, state); } } else { - LOG(TRACE) << config->getInstanceName() << " connect " << remoteAddress.toString() << ": success"; + snode::semantic::appLog().trace() << config->getInstanceName() << " connect " << remoteAddress.toString() << ": success"; if (PhysicalClientSocket::connectInProgress(errno)) { if (enable(physicalClientSocket.getFd())) { - LOG(DEBUG) + snode::semantic::appLog().debug() << config->getInstanceName() << " enable " << remoteAddress.toString(false) << ": success"; } else { - LOG(ERROR) << config->getInstanceName() << " enable " << remoteAddress.toString() + snode::semantic::appLog().error() << config->getInstanceName() << " enable " << remoteAddress.toString() << ": failed. No valid descriptor created"; state = core::socket::STATE(core::socket::STATE_FATAL, ECANCELED, "SocketConnector not enabled"); @@ -188,8 +189,8 @@ namespace core::socket::stream { SocketConnection* socketConnection = new SocketConnection(std::move(physicalClientSocket), onDisconnect, config); - LOG(DEBUG) << config->getInstanceName() << " connect " << remoteAddress.toString() << ": success"; - LOG(DEBUG) << " " << socketConnection->getLocalAddress().toString() << " -> " + snode::semantic::appLog().debug() << config->getInstanceName() << " connect " << remoteAddress.toString() << ": success"; + snode::semantic::appLog().debug() << " " << socketConnection->getLocalAddress().toString() << " -> " << socketConnection->getRemoteAddress().toString(); onStatus(remoteAddress, state); @@ -204,7 +205,7 @@ namespace core::socket::stream { core::socket::State state = core::socket::STATE(badSocketAddress.getState(), badSocketAddress.getErrnum(), badSocketAddress.what()); - LOG(ERROR) << state.what(); + snode::semantic::appLog().error() << state.what(); onStatus({}, state); } @@ -212,12 +213,12 @@ namespace core::socket::stream { core::socket::State state = core::socket::STATE(badSocketAddress.getState(), badSocketAddress.getErrnum(), badSocketAddress.what()); - LOG(ERROR) << state.what(); + snode::semantic::appLog().error() << state.what(); onStatus({}, state); } } else { - LOG(DEBUG) << config->getInstanceName() << ": disabled"; + snode::semantic::appLog().debug() << config->getInstanceName() << ": disabled"; onStatus({}, core::socket::STATE_DISABLED); } @@ -242,8 +243,8 @@ namespace core::socket::stream { if (errno == 0) { SocketConnection* socketConnection = new SocketConnection(std::move(physicalClientSocket), onDisconnect, config); - LOG(DEBUG) << config->getInstanceName() << " connect " << remoteAddress.toString() << ": success"; - LOG(DEBUG) << " " << socketConnection->getLocalAddress().toString() << " -> " + snode::semantic::appLog().debug() << config->getInstanceName() << " connect " << remoteAddress.toString() << ": success"; + snode::semantic::appLog().debug() << " " << socketConnection->getLocalAddress().toString() << " -> " << socketConnection->getRemoteAddress().toString(); onStatus(remoteAddress, core::socket::STATE_OK); @@ -253,7 +254,7 @@ namespace core::socket::stream { disable(); } else if (PhysicalClientSocket::connectInProgress(errno)) { - LOG(DEBUG) << config->getInstanceName() << " connect " << remoteAddress.toString() << ": in progress:"; + snode::semantic::appLog().debug() << config->getInstanceName() << " connect " << remoteAddress.toString() << ": in progress:"; } else { SocketAddress currentRemoteAddress = remoteAddress; @@ -274,18 +275,18 @@ namespace core::socket::stream { } if (remoteAddress.useNext()) { - PLOG(DEBUG) << config->getInstanceName() << " connect '" << remoteAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << config->getInstanceName() << " connect '" << remoteAddress.toString(); onStatus(currentRemoteAddress, (state | core::socket::State::NO_RETRY)); - LOG(DEBUG) << config->getInstanceName() + snode::semantic::appLog().debug() << config->getInstanceName() << " using next SocketAddress: " << config->Remote::getSocketAddress().toString(); useNextSocketAddress(); disable(); } else { - PLOG(DEBUG) << config->getInstanceName() << " connect " << remoteAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << config->getInstanceName() << " connect " << remoteAddress.toString(); onStatus(currentRemoteAddress, state); @@ -293,7 +294,7 @@ namespace core::socket::stream { } } } else { - PLOG(DEBUG) << config->getInstanceName() << " getsockopt syscall error: '" << remoteAddress.toString() << "'"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << config->getInstanceName() << " getsockopt syscall error: '" << remoteAddress.toString() << "'"; onStatus(remoteAddress, core::socket::STATE_FATAL); disable(); @@ -311,16 +312,16 @@ namespace core::socket::stream { typename Config, template typename SocketConnection> void SocketConnector::connectTimeout() { - LOG(TRACE) << config->getInstanceName() << " connect timeout " << remoteAddress.toString(); + snode::semantic::appLog().trace() << config->getInstanceName() << " connect timeout " << remoteAddress.toString(); SocketAddress currentRemoteAddress = remoteAddress; if (remoteAddress.useNext()) { - LOG(DEBUG) << config->getInstanceName() << " using next SocketAddress: '" << config->Remote::getSocketAddress().toString() + snode::semantic::appLog().debug() << config->getInstanceName() << " using next SocketAddress: '" << config->Remote::getSocketAddress().toString() << "'"; useNextSocketAddress(); } else { - LOG(DEBUG) << config->getInstanceName() << " connect timeout '" << remoteAddress.toString() << "'"; + snode::semantic::appLog().debug() << config->getInstanceName() << " connect timeout '" << remoteAddress.toString() << "'"; errno = ETIMEDOUT; onStatus(currentRemoteAddress, core::socket::STATE_ERROR); diff --git a/src/core/socket/stream/SocketContext.cpp b/src/core/socket/stream/SocketContext.cpp index 1d4887ec29..412e3c5095 100644 --- a/src/core/socket/stream/SocketContext.cpp +++ b/src/core/socket/stream/SocketContext.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -128,7 +129,7 @@ namespace core::socket::stream { void SocketContext::onWriteError(int errnum) { errno = errnum; - PLOG(DEBUG) << socketConnection->getConnectionName() << " SocketContext: onWriteError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << socketConnection->getConnectionName() << " SocketContext: onWriteError"; shutdownRead(); } @@ -136,9 +137,9 @@ namespace core::socket::stream { errno = errnum; if (errno == 0) { - LOG(DEBUG) << socketConnection->getConnectionName() << " SocketContext: EOF received"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << " SocketContext: EOF received"; } else { - PLOG(DEBUG) << socketConnection->getConnectionName() << " SocketContext: onReadError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << socketConnection->getConnectionName() << " SocketContext: onReadError"; } shutdownWrite(); } @@ -153,11 +154,11 @@ namespace core::socket::stream { void SocketContext::detach() { onDisconnected(); - LOG(DEBUG) << socketConnection->getConnectionName() << " SocketContext: detached"; - LOG(DEBUG) << " Online Since: " << getOnlineSince(); - LOG(DEBUG) << " Online Duration: " << getOnlineDuration(); - LOG(DEBUG) << " Total Sent: " << getTotalQueued(); - LOG(DEBUG) << " Total Processed: " << getTotalProcessed(); + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << " SocketContext: detached"; + snode::semantic::appLog().debug() << " Online Since: " << getOnlineSince(); + snode::semantic::appLog().debug() << " Online Duration: " << getOnlineDuration(); + snode::semantic::appLog().debug() << " Total Sent: " << getTotalQueued(); + snode::semantic::appLog().debug() << " Total Processed: " << getTotalProcessed(); delete this; } diff --git a/src/core/socket/stream/SocketServer.h b/src/core/socket/stream/SocketServer.h index 70dcb1c1ac..3a7fc58e08 100644 --- a/src/core/socket/stream/SocketServer.h +++ b/src/core/socket/stream/SocketServer.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -120,40 +121,40 @@ namespace core::socket::stream { this->config, std::make_shared(std::forward(args)...), [onConnect](SocketConnection* socketConnection) { // onConnect - LOG(DEBUG) << socketConnection->getConnectionName() << ": OnConnect"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnConnect"; - LOG(DEBUG) << " Local: " << socketConnection->getLocalAddress().toString(); - LOG(DEBUG) << " Peer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << " Local: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(); if (onConnect) { onConnect(socketConnection); } }, [onConnected](SocketConnection* socketConnection) { // onConnected - LOG(DEBUG) << socketConnection->getConnectionName() << ": OnConnected"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnConnected"; - LOG(DEBUG) << " Local: " << socketConnection->getLocalAddress().toString(); - LOG(DEBUG) << " Peer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << " Local: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(); if (onConnected) { onConnected(socketConnection); } }, [onDisconnect](SocketConnection* socketConnection) { // onDisconnect - LOG(DEBUG) << socketConnection->getConnectionName() << ": OnDisconnect"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnDisconnect"; - LOG(DEBUG) << " Local: " << socketConnection->getLocalAddress().toString(); - LOG(DEBUG) << " Peer: " << socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().debug() << " Local: " << socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(); - LOG(DEBUG) << " Online Since: " << socketConnection->getOnlineSince(); - LOG(DEBUG) << " Online Duration: " << socketConnection->getOnlineDuration(); + snode::semantic::appLog().debug() << " Online Since: " << socketConnection->getOnlineSince(); + snode::semantic::appLog().debug() << " Online Duration: " << socketConnection->getOnlineDuration(); - LOG(DEBUG) << " Total Queued: " << socketConnection->getTotalQueued(); - LOG(DEBUG) << " Total Sent: " << socketConnection->getTotalSent(); - LOG(DEBUG) << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent(); - LOG(DEBUG) << " Total Read: " << socketConnection->getTotalRead(); - LOG(DEBUG) << " Total Processed: " << socketConnection->getTotalProcessed(); - LOG(DEBUG) << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed(); + snode::semantic::appLog().debug() << " Total Queued: " << socketConnection->getTotalQueued(); + snode::semantic::appLog().debug() << " Total Sent: " << socketConnection->getTotalSent(); + snode::semantic::appLog().debug() << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent(); + snode::semantic::appLog().debug() << " Total Read: " << socketConnection->getTotalRead(); + snode::semantic::appLog().debug() << " Total Processed: " << socketConnection->getTotalProcessed(); + snode::semantic::appLog().debug() << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed(); if (onDisconnect) { onDisconnect(socketConnection); @@ -183,7 +184,7 @@ namespace core::socket::stream { sharedContext->flowController.startFlow( [config = this->config, sharedContext = this->sharedContext, onStatus, tries, retryTimeoutScale] { if (config->Instance::getParent() != nullptr || !config->Instance::getRequired()) { - LOG(DEBUG) << config->getInstanceName() << ": Initiating listen"; + snode::semantic::appLog().debug() << config->getInstanceName() << ": Initiating listen"; if (core::SNodeC::state() == core::State::RUNNING || core::SNodeC::state() == core::State::INITIALIZED) { new SocketAcceptor( @@ -214,7 +215,7 @@ namespace core::socket::stream { utils::Random::getInRange(-config->getRetryJitter(), config->getRetryJitter()) * relativeRetryTimeout / 100.; - LOG(INFO) + snode::semantic::appLog().info() << config->getInstanceName() << ": Retry listen in " << relativeRetryTimeout << " seconds"; sharedContext->flowController.armRetryTimer( @@ -228,7 +229,7 @@ namespace core::socket::stream { SocketServer(config, sharedContext) .realListen(onStatus, tries + 1, retryTimeoutScale * config->getRetryBase()); } else { - LOG(INFO) << config->getInstanceName() << ": Retry listen disabled during wait"; + snode::semantic::appLog().info() << config->getInstanceName() << ": Retry listen disabled during wait"; } }); } @@ -236,7 +237,7 @@ namespace core::socket::stream { config); } } else { - LOG(FATAL) << config->getInstanceName() << " required"; + snode::semantic::appLog().critical() << config->getInstanceName() << " required"; } }); diff --git a/src/core/socket/stream/SocketWriter.cpp b/src/core/socket/stream/SocketWriter.cpp index 961f8db11a..7baf28b280 100644 --- a/src/core/socket/stream/SocketWriter.cpp +++ b/src/core/socket/stream/SocketWriter.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -116,7 +117,7 @@ namespace core::socket::stream { } if (markShutdown) { - LOG(TRACE) << getName() << ": Shutdown restart"; + snode::semantic::appLog().trace() << getName() << ": Shutdown restart"; doWriteShutdown(onShutdown); } else if (source != nullptr) { source->resume(); @@ -142,10 +143,10 @@ namespace core::socket::stream { source->suspend(); } } else { - LOG(WARNING) << getName() << ": Send while not enabled"; + snode::semantic::appLog().warn() << getName() << ": Send while not enabled"; } } else { - LOG(WARNING) << getName() << ": Send while shutdown in progress: ignoring"; + snode::semantic::appLog().warn() << getName() << ": Send while shutdown in progress: ignoring"; } } @@ -157,15 +158,15 @@ namespace core::socket::stream { success = source != nullptr; if (success) { - LOG(TRACE) << getName() << ": Stream started"; + snode::semantic::appLog().trace() << getName() << ": Stream started"; } else { - LOG(WARNING) << getName() << ": Stream source is nullptr"; + snode::semantic::appLog().warn() << getName() << ": Stream source is nullptr"; } } else { - LOG(WARNING) << getName() << ": Stream while not enabled"; + snode::semantic::appLog().warn() << getName() << ": Stream while not enabled"; } } else { - LOG(WARNING) << getName() << ": Stream while shutdown in progress"; + snode::semantic::appLog().warn() << getName() << ": Stream while shutdown in progress"; } this->source = source; @@ -174,7 +175,7 @@ namespace core::socket::stream { } void SocketWriter::streamEof() { - LOG(TRACE) << getName() << ": Stream EOF"; + snode::semantic::appLog().trace() << getName() << ": Stream EOF"; this->source = nullptr; } @@ -184,11 +185,11 @@ namespace core::socket::stream { SocketWriter::onShutdown = onShutdown; if (writePuffer.empty()) { - LOG(TRACE) << getName() << ": Shutdown start"; + snode::semantic::appLog().trace() << getName() << ": Shutdown start"; doWriteShutdown(onShutdown); } else { markShutdown = true; - LOG(TRACE) << getName() << ": Shutdown delayed due to queued data"; + snode::semantic::appLog().trace() << getName() << ": Shutdown delayed due to queued data"; } } } diff --git a/src/core/socket/stream/tls/SocketAcceptor.hpp b/src/core/socket/stream/tls/SocketAcceptor.hpp index 9a6c3607cc..e62c0bcd46 100644 --- a/src/core/socket/stream/tls/SocketAcceptor.hpp +++ b/src/core/socket/stream/tls/SocketAcceptor.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -75,19 +76,19 @@ namespace core::socket::stream::tls { } }, [socketContextFactory, onConnected](SocketConnection* socketConnection) { // on Connected - LOG(TRACE) << socketConnection->getConnectionName() << " SSL/TLS: Start handshake"; + snode::semantic::appLog().trace() << socketConnection->getConnectionName() << " SSL/TLS: Start handshake"; if (!socketConnection->doSSLHandshake( [socketContextFactory, onConnected, socketConnection]() { // onSuccess - LOG(DEBUG) << socketConnection->getConnectionName() << " SSL/TLS: Handshake success"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << " SSL/TLS: Handshake success"; onConnected(socketConnection); socketConnection->setSocketContext(socketContextFactory); }, [socketConnection]() { // onTimeout - LOG(ERROR) << socketConnection->getConnectionName() << "SSL/TLS: Handshake timed out"; + snode::semantic::appLog().error() << socketConnection->getConnectionName() << "SSL/TLS: Handshake timed out"; socketConnection->close(); }, @@ -96,7 +97,7 @@ namespace core::socket::stream::tls { socketConnection->close(); })) { - LOG(ERROR) << socketConnection->getConnectionName() + " SSL/TLS: Handshake failed"; + snode::semantic::appLog().error() << socketConnection->getConnectionName() + " SSL/TLS: Handshake failed"; socketConnection->close(); } @@ -133,17 +134,17 @@ namespace core::socket::stream::tls { template void SocketAcceptor::init() { if (core::eventLoopState() == core::State::RUNNING && !config->getDisabled()) { - LOG(TRACE) << config->getInstanceName() << " SSL/TLS: SSL_CTX creating ..."; + snode::semantic::appLog().trace() << config->getInstanceName() << " SSL/TLS: SSL_CTX creating ..."; SSL_CTX* sslCtx = config->getSslCtx(); if (sslCtx != nullptr) { - LOG(DEBUG) << config->getInstanceName() << " SSL/TLS: SSL_CTX created"; + snode::semantic::appLog().debug() << config->getInstanceName() << " SSL/TLS: SSL_CTX created"; SSL_CTX_set_client_hello_cb(sslCtx, clientHelloCallback, nullptr); Super::init(); } else { - LOG(ERROR) << config->getInstanceName() << " SSL/TLS: SSL/TLS creation failed"; + snode::semantic::appLog().error() << config->getInstanceName() << " SSL/TLS: SSL/TLS creation failed"; Super::onStatus(Super::config->Local::getSocketAddress(), core::socket::STATE_ERROR); Super::destruct(); @@ -166,19 +167,19 @@ namespace core::socket::stream::tls { SSL_CTX* sniSslCtx = config->getSniCtx(serverNameIndication); if (sniSslCtx != nullptr) { - LOG(DEBUG) << connectionName << " SSL/TLS: Setting sni certificate for '" << serverNameIndication << "'"; + snode::semantic::appLog().debug() << connectionName << " SSL/TLS: Setting sni certificate for '" << serverNameIndication << "'"; core::socket::stream::tls::ssl_set_ssl_ctx(ssl, sniSslCtx); } else if (config->getForceSni()) { - LOG(ERROR) << connectionName << " SSL/TLS: No sni certificate found for '" << serverNameIndication + snode::semantic::appLog().error() << connectionName << " SSL/TLS: No sni certificate found for '" << serverNameIndication << "' but forceSni set - terminating"; ret = SSL_CLIENT_HELLO_ERROR; *al = SSL_AD_UNRECOGNIZED_NAME; } else { - LOG(WARNING) << connectionName << " SSL/TLS: No sni certificate found for '" << serverNameIndication + snode::semantic::appLog().warn() << connectionName << " SSL/TLS: No sni certificate found for '" << serverNameIndication << "'. Still using master certificate"; } } else { - LOG(DEBUG) << connectionName << " SSL/TLS: No sni certificate requested from client. Still using master certificate"; + snode::semantic::appLog().debug() << connectionName << " SSL/TLS: No sni certificate requested from client. Still using master certificate"; } return ret; diff --git a/src/core/socket/stream/tls/SocketConnection.hpp b/src/core/socket/stream/tls/SocketConnection.hpp index 7acf952d47..699d24786e 100644 --- a/src/core/socket/stream/tls/SocketConnection.hpp +++ b/src/core/socket/stream/tls/SocketConnection.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -166,9 +167,9 @@ namespace core::socket::stream::tls { SocketWriter::resume(); } if (SSL_get_shutdown(ssl) == (SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN)) { - LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Passive close_notify received and sent"; + snode::semantic::appLog().debug() << Super::getConnectionName() << " SSL/TLS: Passive close_notify received and sent"; } else { - LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Active close_notify sent"; + snode::semantic::appLog().debug() << Super::getConnectionName() << " SSL/TLS: Active close_notify sent"; } }, [this, resumeSocketReader, resumeSocketWriter]() { // onTimeout @@ -178,7 +179,7 @@ namespace core::socket::stream::tls { if (resumeSocketWriter) { SocketWriter::resume(); } - LOG(ERROR) << Super::getConnectionName() << " SSL/TLS: Shutdown handshake timed out"; + snode::semantic::appLog().error() << Super::getConnectionName() << " SSL/TLS: Shutdown handshake timed out"; Super::doWriteShutdown([this]() { SocketConnection::close(); }); @@ -202,19 +203,19 @@ namespace core::socket::stream::tls { void SocketConnection::onReadShutdown() { if ((SSL_get_shutdown(ssl) & SSL_RECEIVED_SHUTDOWN) != 0) { if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) != 0) { - LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Active close_notify sent and received"; + snode::semantic::appLog().debug() << Super::getConnectionName() << " SSL/TLS: Active close_notify sent and received"; SocketWriter::shutdownInProgress = false; if (closeNotifyIsEOF) { this->onReadError(0); } } else { - LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Passive close_notify received, answering with close_notify"; + snode::semantic::appLog().debug() << Super::getConnectionName() << " SSL/TLS: Passive close_notify received, answering with close_notify"; doSSLShutdown(); } } else { - LOG(ERROR) << Super::getConnectionName() << " SSL/TLS: Unexpected EOF error"; + snode::semantic::appLog().error() << Super::getConnectionName() << " SSL/TLS: Unexpected EOF error"; SocketWriter::shutdownInProgress = false; SSL_set_shutdown(ssl, SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN); @@ -224,7 +225,7 @@ namespace core::socket::stream::tls { template void SocketConnection::doWriteShutdown(const std::function& onShutdown) { if ((SSL_get_shutdown(ssl) & SSL_SENT_SHUTDOWN) == 0) { - LOG(DEBUG) << Super::getConnectionName() << " SSL/TLS: Active send close_notify"; + snode::semantic::appLog().debug() << Super::getConnectionName() << " SSL/TLS: Active send close_notify"; doSSLShutdown(); } else { diff --git a/src/core/socket/stream/tls/SocketConnector.hpp b/src/core/socket/stream/tls/SocketConnector.hpp index d9652fd2ee..e67667b6ce 100644 --- a/src/core/socket/stream/tls/SocketConnector.hpp +++ b/src/core/socket/stream/tls/SocketConnector.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -78,19 +79,19 @@ namespace core::socket::stream::tls { } }, [socketContextFactory, onConnected](SocketConnection* socketConnection) { // onConnected - LOG(TRACE) << socketConnection->getConnectionName() << " SSL/TLS: Start handshake"; + snode::semantic::appLog().trace() << socketConnection->getConnectionName() << " SSL/TLS: Start handshake"; if (!socketConnection->doSSLHandshake( [socketContextFactory, onConnected, socketConnection]() { // onSuccess - LOG(DEBUG) << socketConnection->getConnectionName() << " SSL/TLS: Handshake success"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << " SSL/TLS: Handshake success"; onConnected(socketConnection); socketConnection->setSocketContext(socketContextFactory); }, [socketConnection]() { // onTimeout - LOG(ERROR) << socketConnection->getConnectionName() << " SSL/TLS: Handshake timed out"; + snode::semantic::appLog().error() << socketConnection->getConnectionName() << " SSL/TLS: Handshake timed out"; socketConnection->close(); }, @@ -99,7 +100,7 @@ namespace core::socket::stream::tls { socketConnection->close(); })) { - LOG(ERROR) << socketConnection->getConnectionName() + " SSL/TLS: Handshake failed"; + snode::semantic::appLog().error() << socketConnection->getConnectionName() + " SSL/TLS: Handshake failed"; socketConnection->close(); } @@ -136,14 +137,14 @@ namespace core::socket::stream::tls { template void SocketConnector::init() { if (core::eventLoopState() == core::State::RUNNING && !config->getDisabled()) { - LOG(TRACE) << config->getInstanceName() << " SSL/TLS: SSL_CTX creating ..."; + snode::semantic::appLog().trace() << config->getInstanceName() << " SSL/TLS: SSL_CTX creating ..."; if (config->getSslCtx() != nullptr) { - LOG(DEBUG) << config->getInstanceName() << " SSL/TLS: SSL_CTX created"; + snode::semantic::appLog().debug() << config->getInstanceName() << " SSL/TLS: SSL_CTX created"; Super::init(); } else { - LOG(ERROR) << config->getInstanceName() << " SSL/TLS: SSL_CTX creation failed"; + snode::semantic::appLog().error() << config->getInstanceName() << " SSL/TLS: SSL_CTX creation failed"; Super::onStatus(config->Remote::getSocketAddress(), core::socket::STATE_FATAL); Super::destruct(); diff --git a/src/core/socket/stream/tls/SocketReader.cpp b/src/core/socket/stream/tls/SocketReader.cpp index cd8bdfc3a9..df74dd5955 100644 --- a/src/core/socket/stream/tls/SocketReader.cpp +++ b/src/core/socket/stream/tls/SocketReader.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -74,13 +75,13 @@ namespace core::socket::stream::tls { ret = -1; break; case SSL_ERROR_WANT_WRITE: - LOG(TRACE) << getName() << " SSL/TLS: Start renegotiation on read"; + snode::semantic::appLog().trace() << getName() << " SSL/TLS: Start renegotiation on read"; doSSLHandshake( [this]() { - LOG(DEBUG) << getName() << " SSL/TLS: Renegotiation on read success"; + snode::semantic::appLog().debug() << getName() << " SSL/TLS: Renegotiation on read success"; }, [this]() { - LOG(WARNING) << getName() << " SSL/TLS: Renegotiation on read timed out"; + snode::semantic::appLog().warn() << getName() << " SSL/TLS: Renegotiation on read timed out"; }, [this](int ssl_err) { ssl_log(getName() + " SSL/TLS: Renegotiation on read", ssl_err); @@ -104,9 +105,9 @@ namespace core::socket::stream::tls { const utils::PreserveErrno pe; if (ret == 0) { - PLOG(DEBUG) << getName() << " SSL/TLS: EOF detected: Connection closed by peer."; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << getName() << " SSL/TLS: EOF detected: Connection closed by peer."; } else { - PLOG(WARNING) << getName() + " SSL/TLS: Syscall error on read"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Warning, errno) << getName() + " SSL/TLS: Syscall error on read"; } } ret = -1; diff --git a/src/core/socket/stream/tls/SocketWriter.cpp b/src/core/socket/stream/tls/SocketWriter.cpp index c85323f117..862f18f8db 100644 --- a/src/core/socket/stream/tls/SocketWriter.cpp +++ b/src/core/socket/stream/tls/SocketWriter.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -68,13 +69,13 @@ namespace core::socket::stream::tls { switch (ssl_err) { case SSL_ERROR_WANT_READ: - LOG(TRACE) << getName() << " SSL/TLS: Start renegotiation on read"; + snode::semantic::appLog().trace() << getName() << " SSL/TLS: Start renegotiation on read"; doSSLHandshake( [this]() { - LOG(DEBUG) << getName() << " SSL/TLS: Renegotiation on read success"; + snode::semantic::appLog().debug() << getName() << " SSL/TLS: Renegotiation on read success"; }, [this]() { - LOG(WARNING) << getName() << " SSL/TLS: Renegotiation on read timed out"; + snode::semantic::appLog().warn() << getName() << " SSL/TLS: Renegotiation on read timed out"; }, [this](int ssl_err) { ssl_log(getName() + " SSL/TLS: Renegotiation", ssl_err); @@ -96,11 +97,11 @@ namespace core::socket::stream::tls { const utils::PreserveErrno pe; if (errno == EPIPE) { - PLOG(WARNING) << getName() << " SSL/TLS: Syscal error (SIGPIPE detected) on write."; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Warning, errno) << getName() << " SSL/TLS: Syscal error (SIGPIPE detected) on write."; } else if (errno == ECONNRESET) { - PLOG(WARNING) << getName() << " SSL/TLS: Connection reset by peer (ECONNRESET)."; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Warning, errno) << getName() << " SSL/TLS: Connection reset by peer (ECONNRESET)."; } else { - PLOG(WARNING) << getName() << " SSL/TLS: Syscall error on write"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Warning, errno) << getName() << " SSL/TLS: Syscall error on write"; } } ret = -1; diff --git a/src/core/socket/stream/tls/ssl_utils.cpp b/src/core/socket/stream/tls/ssl_utils.cpp index 746e1d5349..2c27b06b48 100644 --- a/src/core/socket/stream/tls/ssl_utils.cpp +++ b/src/core/socket/stream/tls/ssl_utils.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -87,15 +88,15 @@ namespace core::socket::stream::tls { X509_NAME_oneline(X509_get_issuer_name(curr_cert), issuerName, 256); if (preverify_ok != 0) { - LOG(DEBUG) << connectionName << ": SSL/TLS verify success at depth=" << depth; - LOG(DEBUG) << " Issuer: " << issuerName; - LOG(DEBUG) << " Subject: " << subjectName; + snode::semantic::appLog().debug() << connectionName << ": SSL/TLS verify success at depth=" << depth; + snode::semantic::appLog().debug() << " Issuer: " << issuerName; + snode::semantic::appLog().debug() << " Subject: " << subjectName; } else { const int err = X509_STORE_CTX_get_error(ctx); - LOG(DEBUG) << connectionName << ": SSL/TLS verify error at depth=" << depth << ": " << X509_verify_cert_error_string(err); - LOG(DEBUG) << " Issuer: " << issuerName; - LOG(DEBUG) << " Subject: " << subjectName; + snode::semantic::appLog().debug() << connectionName << ": SSL/TLS verify error at depth=" << depth << ": " << X509_verify_cert_error_string(err); + snode::semantic::appLog().debug() << " Issuer: " << issuerName; + snode::semantic::appLog().debug() << " Subject: " << subjectName; /* * At this point, err contains the last verification error. We can use @@ -137,31 +138,31 @@ namespace core::socket::stream::tls { sslErr = true; } else { if (!sslConfig.caCert.empty()) { - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: CA certificate loaded"; - LOG(TRACE) << " " << sslConfig.caCert; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: CA certificate loaded"; + snode::semantic::appLog().trace() << " " << sslConfig.caCert; } else { - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: CA certificate not loaded from a file"; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: CA certificate not loaded from a file"; } if (!sslConfig.caCertDir.empty()) { - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: CA certificates load from"; - LOG(TRACE) << " " << sslConfig.caCertDir; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: CA certificates load from"; + snode::semantic::appLog().trace() << " " << sslConfig.caCertDir; } else { - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: CA certificates not loaded from a directory"; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: CA certificates not loaded from a directory"; } } } else { - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: CA certificate not loaded from a file"; - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: CA certificates not loaded from a directory"; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: CA certificate not loaded from a file"; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: CA certificates not loaded from a directory"; } if (!sslErr && sslConfig.caCertUseDefaultDir) { if (SSL_CTX_set_default_verify_paths(ctx) == 0) { ssl_log_error(sslConfig.instanceName + " SSL/TLS: CA certificates error load from default openssl CA directory"); sslErr = true; } else { - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: CA certificates enabled load from default openssl CA directory"; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: CA certificates enabled load from default openssl CA directory"; } } else { - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: CA certificates not loaded from default openssl CA directory"; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: CA certificates not loaded from default openssl CA directory"; } if (!sslErr) { SSL_CTX_set_verify_depth(ctx, 5); @@ -172,7 +173,7 @@ namespace core::socket::stream::tls { : 0), verify_callback); if ((SSL_CTX_get_verify_mode(ctx) & SSL_VERIFY_PEER) != 0) { - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: CA requested verify"; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: CA requested verify"; } if (!sslConfig.cert.empty()) { if (SSL_CTX_use_certificate_chain_file(ctx, sslConfig.cert.c_str()) == 0) { @@ -190,14 +191,14 @@ namespace core::socket::stream::tls { } else if (SSL_CTX_check_private_key(ctx) != 1) { ssl_log_error(sslConfig.instanceName + " SSL/TLS: Cert chain key error"); - LOG(TRACE) << " " << sslConfig.certKey; + snode::semantic::appLog().trace() << " " << sslConfig.certKey; sslErr = true; } else { - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: Cert chain key loaded"; - LOG(TRACE) << " " << sslConfig.certKey; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: Cert chain key loaded"; + snode::semantic::appLog().trace() << " " << sslConfig.certKey; - LOG(TRACE) << sslConfig.instanceName << " SSL/TLS: Cert chain loaded"; - LOG(TRACE) << " " << sslConfig.cert; + snode::semantic::appLog().trace() << sslConfig.instanceName << " SSL/TLS: Cert chain loaded"; + snode::semantic::appLog().trace() << " " << sslConfig.cert; } } } @@ -339,32 +340,32 @@ namespace core::socket::stream::tls { } void ssl_log_error(const std::string& message) { - LOG(ERROR) << message; - LOG(ERROR) << " " << ERR_error_string(ERR_get_error(), nullptr); + snode::semantic::appLog().error() << message; + snode::semantic::appLog().error() << " " << ERR_error_string(ERR_get_error(), nullptr); unsigned long errorCode = 0; while ((errorCode = ERR_get_error()) != 0) { - LOG(ERROR) << " " << ERR_error_string(errorCode, nullptr); + snode::semantic::appLog().error() << " " << ERR_error_string(errorCode, nullptr); } } void ssl_log_warning(const std::string& message) { - LOG(WARNING) << message; - LOG(WARNING) << " " << ERR_error_string(ERR_get_error(), nullptr); + snode::semantic::appLog().warn() << message; + snode::semantic::appLog().warn() << " " << ERR_error_string(ERR_get_error(), nullptr); unsigned long errorCode = 0; while ((errorCode = ERR_get_error()) != 0) { - LOG(WARNING) << " " << ERR_error_string(errorCode, nullptr); + snode::semantic::appLog().warn() << " " << ERR_error_string(errorCode, nullptr); } } void ssl_log_info(const std::string& message) { - LOG(INFO) << message; - LOG(INFO) << " " << ERR_error_string(ERR_get_error(), nullptr); + snode::semantic::appLog().info() << message; + snode::semantic::appLog().info() << " " << ERR_error_string(ERR_get_error(), nullptr); unsigned long errorCode = 0; while ((errorCode = ERR_get_error()) != 0) { - LOG(INFO) << " " << ERR_error_string(errorCode, nullptr); + snode::semantic::appLog().info() << " " << ERR_error_string(errorCode, nullptr); } } diff --git a/src/database/mariadb/MariaDBConnection.cpp b/src/database/mariadb/MariaDBConnection.cpp index 5e1af40326..a7a298b69c 100644 --- a/src/database/mariadb/MariaDBConnection.cpp +++ b/src/database/mariadb/MariaDBConnection.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -98,17 +99,17 @@ namespace database::mariadb { ExceptionalConditionEventReceiver::disable(); } - LOG(ERROR) << this->connectionName << " MariaDB: Descriptor not registered in SNode.C eventloop"; + snode::semantic::appLog().error() << this->connectionName << " MariaDB: Descriptor not registered in SNode.C eventloop"; } } }, [this]() { - LOG(DEBUG) << this->connectionName << " MariaDB connect: success"; + snode::semantic::appLog().debug() << this->connectionName << " MariaDB connect: success"; this->onStateChanged({.error = 0, .errorMessage = "", .connected = true}); }, [this](const std::string& errorString, unsigned int errorNumber) { - LOG(WARNING) << this->connectionName << " MariaDB connect: error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().warn() << this->connectionName << " MariaDB connect: error: " << errorString << " : " << errorNumber; this->onStateChanged({.error = errorNumber, .errorMessage = errorString}); })))); @@ -162,7 +163,7 @@ namespace database::mariadb { if (!commandSequenceQueue.empty()) { currentCommand = commandSequenceQueue.front().nextCommand(); - LOG(DEBUG) << connectionName << " MariaDB start: " << currentCommand->commandInfo(); + snode::semantic::appLog().debug() << connectionName << " MariaDB start: " << currentCommand->commandInfo(); currentCommand->setMariaDBConnection(this); checkStatus(currentCommand->commandStart(mysql, currentTime)); @@ -188,7 +189,7 @@ namespace database::mariadb { } void MariaDBConnection::commandCompleted() { - LOG(DEBUG) << connectionName << " MariaDB completed: " << currentCommand->commandInfo(); + snode::semantic::appLog().debug() << connectionName << " MariaDB completed: " << currentCommand->commandInfo(); commandSequenceQueue.front().commandCompleted(); const bool sequenceEmpty = commandSequenceQueue.front().empty(); @@ -299,7 +300,7 @@ namespace database::mariadb { void MariaDBConnection::unobservedEvent() { if (!closing) { - LOG(ERROR) << connectionName << " MariaDB: Lost connection"; + snode::semantic::appLog().error() << connectionName << " MariaDB: Lost connection"; } if (mariaDBClient != nullptr) { diff --git a/src/database/mariadb/MariaDBLibrary.cpp b/src/database/mariadb/MariaDBLibrary.cpp index b4637812e2..90cf421545 100644 --- a/src/database/mariadb/MariaDBLibrary.cpp +++ b/src/database/mariadb/MariaDBLibrary.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -59,7 +60,7 @@ namespace database::mariadb { std::call_once(initOnce, []() { const int rc = mysql_library_init(0, nullptr, nullptr); if (rc != 0) { - LOG(ERROR) << "MariaDB: mysql_library_init failed (rc=" << rc << ")"; + snode::semantic::appLog().error() << "MariaDB: mysql_library_init failed (rc=" << rc << ")"; // Best effort: proceed; subsequent mysql_* calls may fail. } diff --git a/src/express/dispatcher/ApplicationDispatcher.cpp b/src/express/dispatcher/ApplicationDispatcher.cpp index eb542a849d..2b2670f1f6 100644 --- a/src/express/dispatcher/ApplicationDispatcher.cpp +++ b/src/express/dispatcher/ApplicationDispatcher.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,16 +71,16 @@ namespace express::dispatcher { bool strictRouting, bool caseInsensitiveRouting, bool mergeParams) { - LOG(TRACE) << "======================= APPLICATION DISPATCH ======================="; - LOG(TRACE) << controller.getResponse()->getSocketContext()->getSocketConnection()->getConnectionName(); - LOG(TRACE) << " Request Method: " << controller.getRequest()->method; - LOG(TRACE) << " Request Url: " << controller.getRequest()->url; - LOG(TRACE) << " Request Path: " << controller.getRequest()->path; - LOG(TRACE) << " Mountpoint Method: " << mountPoint.method; - LOG(TRACE) << " Mountpoint Path: " << mountPoint.relativeMountPath; - LOG(TRACE) << " StrictRouting: " << strictRouting; - LOG(TRACE) << " CaseInsensitiveRouting: " << caseInsensitiveRouting; - LOG(TRACE) << " MergeParams: " << mergeParams; + snode::semantic::appLog().trace() << "======================= APPLICATION DISPATCH ======================="; + snode::semantic::appLog().trace() << controller.getResponse()->getSocketContext()->getSocketConnection()->getConnectionName(); + snode::semantic::appLog().trace() << " Request Method: " << controller.getRequest()->method; + snode::semantic::appLog().trace() << " Request Url: " << controller.getRequest()->url; + snode::semantic::appLog().trace() << " Request Path: " << controller.getRequest()->path; + snode::semantic::appLog().trace() << " Mountpoint Method: " << mountPoint.method; + snode::semantic::appLog().trace() << " Mountpoint Path: " << mountPoint.relativeMountPath; + snode::semantic::appLog().trace() << " StrictRouting: " << strictRouting; + snode::semantic::appLog().trace() << " CaseInsensitiveRouting: " << caseInsensitiveRouting; + snode::semantic::appLog().trace() << " MergeParams: " << mergeParams; bool dispatched = false; @@ -91,7 +92,7 @@ namespace express::dispatcher { matchMountPoint(controller, mountPoint.relativeMountPath, mountPoint, regex, names, strictRouting, caseInsensitiveRouting); if (match.requestMatched) { - LOG(TRACE) << "----------------------- APPLICATION MATCH -----------------------"; + snode::semantic::appLog().trace() << "----------------------- APPLICATION MATCH -----------------------"; dispatched = true; @@ -113,10 +114,10 @@ namespace express::dispatcher { } } else { - LOG(TRACE) << "----------------------- APPLICATION NOMATCH -----------------------"; + snode::semantic::appLog().trace() << "----------------------- APPLICATION NOMATCH -----------------------"; } } else { - LOG(TRACE) << "----------------------- APPLICATION NOMATCH -----------------------"; + snode::semantic::appLog().trace() << "----------------------- APPLICATION NOMATCH -----------------------"; } return dispatched; diff --git a/src/express/dispatcher/MiddlewareDispatcher.cpp b/src/express/dispatcher/MiddlewareDispatcher.cpp index a151089ad8..0f958363c4 100644 --- a/src/express/dispatcher/MiddlewareDispatcher.cpp +++ b/src/express/dispatcher/MiddlewareDispatcher.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,16 +71,16 @@ namespace express::dispatcher { bool strictRouting, bool caseInsensitiveRouting, bool mergeParams) { - LOG(TRACE) << "======================= MIDDLEWARE DISPATCH ======================="; - LOG(TRACE) << controller.getResponse()->getSocketContext()->getSocketConnection()->getConnectionName(); - LOG(TRACE) << " Request Method: " << controller.getRequest()->method; - LOG(TRACE) << " Request Url: " << controller.getRequest()->url; - LOG(TRACE) << " Request Path: " << controller.getRequest()->path; - LOG(TRACE) << " Mountpoint Method: " << mountPoint.method; - LOG(TRACE) << " Mountpoint Path: " << mountPoint.relativeMountPath; - LOG(TRACE) << " StrictRouting: " << strictRouting; - LOG(TRACE) << " CaseInsensitiveRouting: " << caseInsensitiveRouting; - LOG(TRACE) << " MergeParams: " << mergeParams; + snode::semantic::appLog().trace() << "======================= MIDDLEWARE DISPATCH ======================="; + snode::semantic::appLog().trace() << controller.getResponse()->getSocketContext()->getSocketConnection()->getConnectionName(); + snode::semantic::appLog().trace() << " Request Method: " << controller.getRequest()->method; + snode::semantic::appLog().trace() << " Request Url: " << controller.getRequest()->url; + snode::semantic::appLog().trace() << " Request Path: " << controller.getRequest()->path; + snode::semantic::appLog().trace() << " Mountpoint Method: " << mountPoint.method; + snode::semantic::appLog().trace() << " Mountpoint Path: " << mountPoint.relativeMountPath; + snode::semantic::appLog().trace() << " StrictRouting: " << strictRouting; + snode::semantic::appLog().trace() << " CaseInsensitiveRouting: " << caseInsensitiveRouting; + snode::semantic::appLog().trace() << " MergeParams: " << mergeParams; bool dispatched = false; @@ -91,7 +92,7 @@ namespace express::dispatcher { matchMountPoint(controller, mountPoint.relativeMountPath, mountPoint, regex, names, strictRouting, caseInsensitiveRouting); if (match.requestMatched) { - LOG(TRACE) << "----------------------- MIDDLEWARE MATCH -----------------------"; + snode::semantic::appLog().trace() << "----------------------- MIDDLEWARE MATCH -----------------------"; dispatched = true; @@ -109,7 +110,7 @@ namespace express::dispatcher { // If next() was called synchronously continue current route-tree traversal if ((next.controller.getFlags() & express::Controller::NEXT) != 0) { - LOG(TRACE) << "Express: M - Next called - set to NO MATCH"; + snode::semantic::appLog().trace() << "Express: M - Next called - set to NO MATCH"; dispatched = false; controller = next.controller; } @@ -121,10 +122,10 @@ namespace express::dispatcher { } } else { - LOG(TRACE) << "----------------------- MIDDLEWARE NOMATCH -----------------------"; + snode::semantic::appLog().trace() << "----------------------- MIDDLEWARE NOMATCH -----------------------"; } } else { - LOG(TRACE) << "----------------------- MIDDLEWARE NOMATCH -----------------------"; + snode::semantic::appLog().trace() << "----------------------- MIDDLEWARE NOMATCH -----------------------"; } return dispatched; diff --git a/src/express/dispatcher/RouterDispatcher.cpp b/src/express/dispatcher/RouterDispatcher.cpp index 90f1dea441..cb0a6055de 100644 --- a/src/express/dispatcher/RouterDispatcher.cpp +++ b/src/express/dispatcher/RouterDispatcher.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -69,16 +70,16 @@ namespace express::dispatcher { [[maybe_unused]] bool strictRoutingUnused, [[maybe_unused]] bool caseInsensitiveRoutingUnused, [[maybe_unused]] bool mergeParamsUnused) { - LOG(TRACE) << "======================= ROUTER DISPATCH ======================="; - LOG(TRACE) << controller.getResponse()->getSocketContext()->getSocketConnection()->getConnectionName(); - LOG(TRACE) << " Request Method: " << controller.getRequest()->method; - LOG(TRACE) << " Request Url: " << controller.getRequest()->url; - LOG(TRACE) << " Request Path: " << controller.getRequest()->path; - LOG(TRACE) << " Mountpoint Method: " << mountPoint.method; - LOG(TRACE) << " Mountpoint Path: " << mountPoint.relativeMountPath; - LOG(TRACE) << " StrictRouting: " << this->strictRouting; - LOG(TRACE) << " CaseInsensitiveRouting: " << this->caseInsensitiveRouting; - LOG(TRACE) << " MergeParams: " << this->mergeParams; + snode::semantic::appLog().trace() << "======================= ROUTER DISPATCH ======================="; + snode::semantic::appLog().trace() << controller.getResponse()->getSocketContext()->getSocketConnection()->getConnectionName(); + snode::semantic::appLog().trace() << " Request Method: " << controller.getRequest()->method; + snode::semantic::appLog().trace() << " Request Url: " << controller.getRequest()->url; + snode::semantic::appLog().trace() << " Request Path: " << controller.getRequest()->path; + snode::semantic::appLog().trace() << " Mountpoint Method: " << mountPoint.method; + snode::semantic::appLog().trace() << " Mountpoint Path: " << mountPoint.relativeMountPath; + snode::semantic::appLog().trace() << " StrictRouting: " << this->strictRouting; + snode::semantic::appLog().trace() << " CaseInsensitiveRouting: " << this->caseInsensitiveRouting; + snode::semantic::appLog().trace() << " MergeParams: " << this->mergeParams; bool dispatched = false; @@ -89,7 +90,7 @@ namespace express::dispatcher { controller, mountPoint.relativeMountPath, mountPoint, regex, names, this->strictRouting, this->caseInsensitiveRouting); if (match.requestMatched) { - LOG(TRACE) << "----------------------- ROUTER MATCH -----------------------"; + snode::semantic::appLog().trace() << "----------------------- ROUTER MATCH -----------------------"; dispatched = true; @@ -112,10 +113,10 @@ namespace express::dispatcher { controller.getResponse()->sendStatus(400); } } else { - LOG(TRACE) << "----------------------- ROUTER NOMATCH -----------------------"; + snode::semantic::appLog().trace() << "----------------------- ROUTER NOMATCH -----------------------"; } } else { - LOG(TRACE) << "----------------------- ROUTER NOMATCH -----------------------"; + snode::semantic::appLog().trace() << "----------------------- ROUTER NOMATCH -----------------------"; } return dispatched; diff --git a/src/express/express-compat-suite/snodec/0001-add-express-compat-server.patch b/src/express/express-compat-suite/snodec/0001-add-express-compat-server.patch index 8a99401b3b..48b47691d3 100644 --- a/src/express/express-compat-suite/snodec/0001-add-express-compat-server.patch +++ b/src/express/express-compat-suite/snodec/0001-add-express-compat-server.patch @@ -263,16 +263,16 @@ new file mode 100644 + [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { + switch (state) { + case core::socket::State::OK: -+ VLOG(1) << "express-compat listening on '" << socketAddress.toString() << "'"; ++ snode::semantic::appLog().trace() << "express-compat listening on '" << socketAddress.toString() << "'"; + break; + case core::socket::State::DISABLED: -+ VLOG(1) << "express-compat disabled"; ++ snode::semantic::appLog().trace() << "express-compat disabled"; + break; + case core::socket::State::ERROR: -+ LOG(ERROR) << "express-compat " << socketAddress.toString() << ": " << state.what(); ++ snode::semantic::appLog().error() << "express-compat " << socketAddress.toString() << ": " << state.what(); + break; + case core::socket::State::FATAL: -+ LOG(FATAL) << "express-compat " << socketAddress.toString() << ": " << state.what(); ++ snode::semantic::appLog().critical() << "express-compat " << socketAddress.toString() << ": " << state.what(); + break; + } + }); diff --git a/src/express/legacy/in/Server.cpp b/src/express/legacy/in/Server.cpp index 39ba2241c7..fec4c9b260 100644 --- a/src/express/legacy/in/Server.cpp +++ b/src/express/legacy/in/Server.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,26 +71,26 @@ namespace express::legacy::in { } else { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - VLOG(1) << "Instance: " << instanceName; + snode::semantic::appLog().trace() << "Instance: " << instanceName; for (std::string& route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } return webApp; diff --git a/src/express/legacy/in6/Server.cpp b/src/express/legacy/in6/Server.cpp index f5d9cc8803..658c6c42c3 100644 --- a/src/express/legacy/in6/Server.cpp +++ b/src/express/legacy/in6/Server.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,26 +71,26 @@ namespace express::legacy::in6 { } else { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - VLOG(1) << "Instance: " << instanceName; + snode::semantic::appLog().trace() << "Instance: " << instanceName; for (std::string& route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } return webApp; diff --git a/src/express/legacy/rc/Server.cpp b/src/express/legacy/rc/Server.cpp index 90fdb1f471..a800f127f7 100644 --- a/src/express/legacy/rc/Server.cpp +++ b/src/express/legacy/rc/Server.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,26 +71,26 @@ namespace express::legacy::rc { } else { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - VLOG(1) << "Instance: " << instanceName; + snode::semantic::appLog().trace() << "Instance: " << instanceName; for (std::string& route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } return webApp; diff --git a/src/express/legacy/un/Server.cpp b/src/express/legacy/un/Server.cpp index 006ccacab1..4378cac844 100644 --- a/src/express/legacy/un/Server.cpp +++ b/src/express/legacy/un/Server.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,26 +71,26 @@ namespace express::legacy::un { } else { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - VLOG(1) << "Instance: " << instanceName; + snode::semantic::appLog().trace() << "Instance: " << instanceName; for (std::string& route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } return webApp; diff --git a/src/express/middleware/StaticMiddleware.cpp b/src/express/middleware/StaticMiddleware.cpp index 1bfcd04bfa..2c0d84f247 100644 --- a/src/express/middleware/StaticMiddleware.cpp +++ b/src/express/middleware/StaticMiddleware.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -66,7 +67,7 @@ namespace express::middleware { &stdCookies = this->stdCookies, &connectionState = this->defaultConnectionState, &fallThrough = this->fallThrough] MIDDLEWARE(req, res, next) { - LOG(DEBUG) << res->getSocketContext()->getSocketConnection()->getConnectionName() << " Express " << req->method; + snode::semantic::appLog().debug() << res->getSocketContext()->getSocketConnection()->getConnectionName() << " Express " << req->method; if (req->method != "GET") { if (fallThrough) { @@ -94,7 +95,7 @@ namespace express::middleware { if (index.empty()) { res->status(404).send("Unsupported resource: " + req->url + "\n"); } else { - LOG(INFO) << res->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().info() << res->getSocketContext()->getSocketConnection()->getConnectionName() << " Express StaticMiddleware Redirecting: " << req->url << " -> " << req->originalPath + (!req->originalPath.empty() && req->originalPath.back() != '/' && index.front() != '/' ? "/" @@ -113,10 +114,10 @@ namespace express::middleware { const std::string decodedPath = httputils::url_decode(req->path); res->sendFile(root + decodedPath, [&root, decodedPath, req, res, &next, &fallThrough](int ret) { if (ret == 0) { - LOG(INFO) << res->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().info() << res->getSocketContext()->getSocketConnection()->getConnectionName() << " Express StaticMiddleware: GET " << req->url + " -> " << root + decodedPath; } else { - PLOG(ERROR) << res->getSocketContext()->getSocketConnection()->getConnectionName() << " Express StaticMiddleware " + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << res->getSocketContext()->getSocketConnection()->getConnectionName() << " Express StaticMiddleware " << req->url + " -> " << root + decodedPath; if (fallThrough) { diff --git a/src/express/middleware/VerboseRequest.cpp b/src/express/middleware/VerboseRequest.cpp index 6276d8ae8c..e3a4936bb7 100644 --- a/src/express/middleware/VerboseRequest.cpp +++ b/src/express/middleware/VerboseRequest.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -57,7 +58,7 @@ namespace express::middleware { VerboseRequest::VerboseRequest(Details details) { use("/", [details] MIDDLEWARE(req, res, next) { - LOG(DEBUG) << res->getSocketContext()->getSocketConnection()->getConnectionName() + snode::semantic::appLog().debug() << res->getSocketContext()->getSocketConnection()->getConnectionName() << " Express VerboseMiddleware: " << req->method << " " << req->url << " " << req->httpVersion << "\n" << httputils::toString( req->method, diff --git a/src/express/tls/in/Server.cpp b/src/express/tls/in/Server.cpp index 601ca592fc..9e75d2fc49 100644 --- a/src/express/tls/in/Server.cpp +++ b/src/express/tls/in/Server.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,26 +71,26 @@ namespace express::tls::in { } else { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - VLOG(1) << "Instance: " << instanceName; + snode::semantic::appLog().trace() << "Instance: " << instanceName; for (std::string& route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } return webApp; diff --git a/src/express/tls/in6/Server.cpp b/src/express/tls/in6/Server.cpp index 8afe1c90eb..7afc7dcce6 100644 --- a/src/express/tls/in6/Server.cpp +++ b/src/express/tls/in6/Server.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,26 +71,26 @@ namespace express::tls::in6 { } else { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - VLOG(1) << "Instance: " << instanceName; + snode::semantic::appLog().trace() << "Instance: " << instanceName; for (std::string& route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } return webApp; diff --git a/src/express/tls/rc/Server.cpp b/src/express/tls/rc/Server.cpp index 17d10ead06..17d78e7e4c 100644 --- a/src/express/tls/rc/Server.cpp +++ b/src/express/tls/rc/Server.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,26 +71,26 @@ namespace express::tls::rc { } else { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - VLOG(1) << "Instance: " << instanceName; + snode::semantic::appLog().trace() << "Instance: " << instanceName; for (std::string& route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } return webApp; diff --git a/src/express/tls/un/Server.cpp b/src/express/tls/un/Server.cpp index 353dbf123b..bbce312339 100644 --- a/src/express/tls/un/Server.cpp +++ b/src/express/tls/un/Server.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -70,26 +71,26 @@ namespace express::tls::un { } else { switch (state) { case core::socket::State::OK: - VLOG(1) << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::semantic::appLog().trace() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - VLOG(1) << instanceName << ": disabled"; + snode::semantic::appLog().trace() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - VLOG(1) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().trace() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - VLOG(1) << "Instance: " << instanceName; + snode::semantic::appLog().trace() << "Instance: " << instanceName; for (std::string& route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); - VLOG(1) << " " << route; + snode::semantic::appLog().trace() << " " << route; } return webApp; diff --git a/src/iot/mqtt/Mqtt.cpp b/src/iot/mqtt/Mqtt.cpp index 907f010829..d8ac0ae3ec 100644 --- a/src/iot/mqtt/Mqtt.cpp +++ b/src/iot/mqtt/Mqtt.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -92,7 +93,7 @@ namespace iot::mqtt { } void Mqtt::onConnected() { - LOG(INFO) << "MQTT: Connected"; + snode::semantic::appLog().info() << "MQTT: Connected"; } std::size_t Mqtt::onReceivedFromPeer() { @@ -116,13 +117,13 @@ namespace iot::mqtt { fixedHeader.reset(); if (controlPacketDeserializer == nullptr) { - LOG(DEBUG) << connectionName << " MQTT: Received packet-type is unavailable ... closing connection"; + snode::semantic::appLog().debug() << connectionName << " MQTT: Received packet-type is unavailable ... closing connection"; mqttContext->close(); break; } if (controlPacketDeserializer->isError()) { - LOG(DEBUG) << connectionName << " MQTT: Fixed header has error ... closing connection"; + snode::semantic::appLog().debug() << connectionName << " MQTT: Fixed header has error ... closing connection"; delete controlPacketDeserializer; controlPacketDeserializer = nullptr; @@ -138,7 +139,7 @@ namespace iot::mqtt { consumed += controlPacketDeserializer->deserialize(mqttContext); if (controlPacketDeserializer->isError()) { - LOG(DEBUG) << connectionName << " MQTT: Control packet has error ... closing connection"; + snode::semantic::appLog().debug() << connectionName << " MQTT: Control packet has error ... closing connection"; mqttContext->close(); delete controlPacketDeserializer; @@ -163,7 +164,7 @@ namespace iot::mqtt { } void Mqtt::onDisconnected() { - LOG(INFO) << connectionName << " MQTT: Disconnected"; + snode::semantic::appLog().info() << connectionName << " MQTT: Disconnected"; } const std::string& Mqtt::getConnectionName() const { @@ -174,13 +175,13 @@ namespace iot::mqtt { this->session = session; for (const auto& [packetIdentifier, publish] : session->outgoingPublishMap) { - LOG(INFO) << connectionName << " MQTT: PUBLISH Resend"; + snode::semantic::appLog().info() << connectionName << " MQTT: PUBLISH Resend"; send(publish); } for (const uint16_t packetIdentifier : session->pubrelPacketIdentifierSet) { - LOG(INFO) << connectionName << " MQTT: PUBREL Resend"; + snode::semantic::appLog().info() << connectionName << " MQTT: PUBREL Resend"; sendPubrel(packetIdentifier); } @@ -188,11 +189,11 @@ namespace iot::mqtt { if (keepAlive > 0) { keepAlive *= 1.5; - LOG(INFO) << connectionName << " MQTT: Keep alive initialized with: " << keepAlive; + snode::semantic::appLog().info() << connectionName << " MQTT: Keep alive initialized with: " << keepAlive; keepAliveTimer = core::timer::Timer::singleshotTimer( [this, keepAlive]() { - LOG(ERROR) << connectionName << " MQTT: Keep-alive timer expired. Interval was: " << keepAlive; + snode::semantic::appLog().error() << connectionName << " MQTT: Keep-alive timer expired. Interval was: " << keepAlive; mqttContext->close(); }, keepAlive); @@ -202,13 +203,13 @@ namespace iot::mqtt { } void Mqtt::send(const ControlPacket& controlPacket) const { - LOG(INFO) << connectionName << " MQTT: " << controlPacket.getName() << " send: " << clientId; + snode::semantic::appLog().info() << connectionName << " MQTT: " << controlPacket.getName() << " send: " << clientId; send(controlPacket.serialize()); } void Mqtt::send(const std::vector& data) const { - LOG(TRACE) << connectionName << " MQTT: Send data (full message):\n" << toHexString(data); + snode::semantic::appLog().trace() << connectionName << " MQTT: Send data (full message):\n" << toHexString(data); mqttContext->send(data.data(), data.size()); } @@ -218,12 +219,12 @@ namespace iot::mqtt { send(iot::mqtt::packets::Publish(packetIdentifier, topic, message, qoS, false, retain)); - LOG(INFO) << connectionName << " MQTT: Topic: " << topic; - LOG(INFO) << connectionName << " MQTT: Message:\n" << toHexString(message); - LOG(DEBUG) << connectionName << " MQTT: QoS: " << static_cast(qoS); - LOG(DEBUG) << connectionName << " MQTT: PacketIdentifier: " << packetIdentifier; - LOG(DEBUG) << connectionName << " MQTT: DUP: " << false; - LOG(DEBUG) << connectionName << " MQTT: Retain: " << retain; + snode::semantic::appLog().info() << connectionName << " MQTT: Topic: " << topic; + snode::semantic::appLog().info() << connectionName << " MQTT: Message:\n" << toHexString(message); + snode::semantic::appLog().debug() << connectionName << " MQTT: QoS: " << static_cast(qoS); + snode::semantic::appLog().debug() << connectionName << " MQTT: PacketIdentifier: " << packetIdentifier; + snode::semantic::appLog().debug() << connectionName << " MQTT: DUP: " << false; + snode::semantic::appLog().debug() << connectionName << " MQTT: Retain: " << retain; if (qoS >= 1) { session->outgoingPublishMap.insert_or_assign(packetIdentifier, @@ -265,23 +266,23 @@ namespace iot::mqtt { bool Mqtt::_onPublish(const iot::mqtt::packets::Publish& publish) { bool deliver = true; - LOG(INFO) << connectionName << " MQTT: Topic: " << publish.getTopic(); - LOG(INFO) << connectionName << " MQTT: Message:\n" << toHexString(publish.getMessage()); - LOG(DEBUG) << connectionName << " MQTT: QoS: " << static_cast(publish.getQoS()); - LOG(DEBUG) << connectionName << " MQTT: PacketIdentifier: " << publish.getPacketIdentifier(); - LOG(DEBUG) << connectionName << " MQTT: DUP: " << publish.getDup(); - LOG(DEBUG) << connectionName << " MQTT: Retain: " << publish.getRetain(); + snode::semantic::appLog().info() << connectionName << " MQTT: Topic: " << publish.getTopic(); + snode::semantic::appLog().info() << connectionName << " MQTT: Message:\n" << toHexString(publish.getMessage()); + snode::semantic::appLog().debug() << connectionName << " MQTT: QoS: " << static_cast(publish.getQoS()); + snode::semantic::appLog().debug() << connectionName << " MQTT: PacketIdentifier: " << publish.getPacketIdentifier(); + snode::semantic::appLog().debug() << connectionName << " MQTT: DUP: " << publish.getDup(); + snode::semantic::appLog().debug() << connectionName << " MQTT: Retain: " << publish.getRetain(); if (publish.getQoS() > 2) { - LOG(ERROR) << connectionName << " MQTT: Received invalid QoS: " << publish.getQoS(); + snode::semantic::appLog().error() << connectionName << " MQTT: Received invalid QoS: " << publish.getQoS(); mqttContext->close(); deliver = false; } else if (publish.getPacketIdentifier() == 0 && publish.getQoS() > 0) { - LOG(ERROR) << connectionName << " MQTT: Received QoS > 0 but no PackageIdentifier present"; + snode::semantic::appLog().error() << connectionName << " MQTT: Received QoS > 0 but no PackageIdentifier present"; mqttContext->close(); deliver = false; } else if (publish.getQoS() == 0 && publish.getDup()) { - LOG(ERROR) << connectionName << " MQTT: Received QoS == 0 but dup is set"; + snode::semantic::appLog().error() << connectionName << " MQTT: Received QoS == 0 but dup is set"; mqttContext->close(); deliver = false; } else { @@ -301,13 +302,13 @@ namespace iot::mqtt { if (!publish.getDup()) { session->pubcompPacketIdentifierSet.erase(pid); } else { - LOG(WARNING) << connectionName << " MQTT: Duplicate QoS2 PUBLISH after PUBCOMP for PacketIdentifier: " << pid; + snode::semantic::appLog().warn() << connectionName << " MQTT: Duplicate QoS2 PUBLISH after PUBCOMP for PacketIdentifier: " << pid; break; } } if (session->incomingPublishMap.contains(pid)) { - LOG(INFO) << connectionName << " MQTT: Duplicate QoS2 PUBLISH suppressed for PacketIdentifier: " << pid; + snode::semantic::appLog().info() << connectionName << " MQTT: Duplicate QoS2 PUBLISH suppressed for PacketIdentifier: " << pid; } else { session->incomingPublishMap.emplace(pid, publish); } @@ -321,10 +322,10 @@ namespace iot::mqtt { void Mqtt::_onPuback(const iot::mqtt::packets::Puback& puback) { if (puback.getPacketIdentifier() == 0) { - LOG(ERROR) << connectionName << " MQTT: PackageIdentifier missing"; + snode::semantic::appLog().error() << connectionName << " MQTT: PackageIdentifier missing"; mqttContext->close(); } else { - LOG(DEBUG) << connectionName << " MQTT: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) + snode::semantic::appLog().debug() << connectionName << " MQTT: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << puback.getPacketIdentifier() << std::dec; session->outgoingPublishMap.erase(puback.getPacketIdentifier()); @@ -335,10 +336,10 @@ namespace iot::mqtt { void Mqtt::_onPubrec(const iot::mqtt::packets::Pubrec& pubrec) { if (pubrec.getPacketIdentifier() == 0) { - LOG(ERROR) << connectionName << " MQTT: PackageIdentifier missing"; + snode::semantic::appLog().error() << connectionName << " MQTT: PackageIdentifier missing"; mqttContext->close(); } else { - LOG(DEBUG) << connectionName << " MQTT: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) + snode::semantic::appLog().debug() << connectionName << " MQTT: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << pubrec.getPacketIdentifier() << std::dec; session->outgoingPublishMap.erase(pubrec.getPacketIdentifier()); @@ -352,25 +353,25 @@ namespace iot::mqtt { void Mqtt::_onPubrel(const iot::mqtt::packets::Pubrel& pubrel) { if (pubrel.getPacketIdentifier() == 0) { - LOG(ERROR) << connectionName << " MQTT: PackageIdentifier missing"; + snode::semantic::appLog().error() << connectionName << " MQTT: PackageIdentifier missing"; mqttContext->close(); } else { - LOG(DEBUG) << connectionName << " MQTT: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) + snode::semantic::appLog().debug() << connectionName << " MQTT: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << pubrel.getPacketIdentifier() << std::dec; const uint16_t pid = pubrel.getPacketIdentifier(); if (session->incomingPublishMap.contains(pid)) { - LOG(INFO) << connectionName << " MQTT: QoS2 PUBREL received. Deliver publish: " << pid; + snode::semantic::appLog().info() << connectionName << " MQTT: QoS2 PUBREL received. Deliver publish: " << pid; distributePublish(session->incomingPublishMap[pid]); session->incomingPublishMap.erase(pid); session->pubcompPacketIdentifierSet.insert(pid); } else if (session->pubcompPacketIdentifierSet.contains(pid)) { - LOG(INFO) << connectionName << " MQTT: Duplicate QoS2 PUBREL for completed PacketIdentifier: " << pid; + snode::semantic::appLog().info() << connectionName << " MQTT: Duplicate QoS2 PUBREL for completed PacketIdentifier: " << pid; } else { - LOG(WARNING) << connectionName << " MQTT: QoS2 PUBREL received for unknown PacketIdentifier: " << pid; + snode::semantic::appLog().warn() << connectionName << " MQTT: QoS2 PUBREL received for unknown PacketIdentifier: " << pid; session->pubcompPacketIdentifierSet.insert(pid); } @@ -383,10 +384,10 @@ namespace iot::mqtt { void Mqtt::_onPubcomp(const iot::mqtt::packets::Pubcomp& pubcomp) { if (pubcomp.getPacketIdentifier() == 0) { - LOG(ERROR) << connectionName << " MQTT: PackageIdentifier missing"; + snode::semantic::appLog().error() << connectionName << " MQTT: PackageIdentifier missing"; mqttContext->close(); } else { - LOG(DEBUG) << connectionName << " MQTT: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) + snode::semantic::appLog().debug() << connectionName << " MQTT: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << pubcomp.getPacketIdentifier() << std::dec; session->outgoingPublishMap.erase(pubcomp.getPacketIdentifier()); @@ -397,25 +398,25 @@ namespace iot::mqtt { } void Mqtt::printVP(const iot::mqtt::ControlPacket& packet) const { - LOG(INFO) << connectionName << " MQTT: " << packet.getName() << " received: " << clientId; + snode::semantic::appLog().info() << connectionName << " MQTT: " << packet.getName() << " received: " << clientId; const std::string hexString = toHexString(packet.serializeVP()); if (!hexString.empty()) { - LOG(TRACE) << connectionName << " MQTT: Received data (variable header and payload):\n" << hexString; + snode::semantic::appLog().trace() << connectionName << " MQTT: Received data (variable header and payload):\n" << hexString; } } void Mqtt::printFixedHeader(const FixedHeader& fixedHeader) const { - LOG(INFO) << connectionName << " MQTT: ===================================="; + snode::semantic::appLog().info() << connectionName << " MQTT: ===================================="; - LOG(TRACE) << connectionName << " MQTT: Received data (fixed header):\n" << toHexString(fixedHeader.serialize()); + snode::semantic::appLog().trace() << connectionName << " MQTT: Received data (fixed header):\n" << toHexString(fixedHeader.serialize()); - LOG(DEBUG) << connectionName << " MQTT: Fixed Header: PacketType: 0x" << std::hex << std::setfill('0') << std::setw(2) + snode::semantic::appLog().debug() << connectionName << " MQTT: Fixed Header: PacketType: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(fixedHeader.getType()) << " (" << iot::mqtt::mqttPackageName[fixedHeader.getType()] << ")" << std::dec; - LOG(DEBUG) << connectionName << " MQTT: PacketFlags: 0x" << std::hex << std::setfill('0') << std::setw(2) + snode::semantic::appLog().debug() << connectionName << " MQTT: PacketFlags: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(fixedHeader.getFlags()) << std::dec; - LOG(DEBUG) << connectionName << " MQTT: RemainingLength: " << fixedHeader.getRemainingLength(); + snode::semantic::appLog().debug() << connectionName << " MQTT: RemainingLength: " << fixedHeader.getRemainingLength(); } std::string Mqtt::toHexString(const std::vector& data) { diff --git a/src/iot/mqtt/SubProtocol.hpp b/src/iot/mqtt/SubProtocol.hpp index 64d30c28c9..e357670bc3 100644 --- a/src/iot/mqtt/SubProtocol.hpp +++ b/src/iot/mqtt/SubProtocol.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -104,17 +105,17 @@ namespace iot::mqtt { template void SubProtocol::onConnected() { - LOG(INFO) << getSocketConnection()->getConnectionName() << " WsMqtt: connected:"; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " WsMqtt: connected:"; iot::mqtt::MqttContext::onConnected(); } template void SubProtocol::onMessageStart(int opCode) { if (opCode == web::websocket::SubProtocolContext::OpCode::TEXT) { - LOG(ERROR) << getSocketConnection()->getConnectionName() << " WsMqtt: Wrong Opcode: " << opCode << " (TEXT)"; + snode::semantic::appLog().error() << getSocketConnection()->getConnectionName() << " WsMqtt: Wrong Opcode: " << opCode << " (TEXT)"; this->close(); } else { - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WsMqtt: Message START: " << opCode << " (BIN)"; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " WsMqtt: Message START: " << opCode << " (BIN)"; } } @@ -122,13 +123,13 @@ namespace iot::mqtt { void SubProtocol::onMessageData(const char* chunk, std::size_t chunkLen) { data.append(std::string(chunk, chunkLen)); - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WsMqtt: Frame Data:\n" + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " WsMqtt: Frame Data:\n" << std::string(32, ' ').append(utils::hexDump(std::vector(chunk, chunk + chunkLen), 32)); } template void SubProtocol::onMessageEnd() { - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WsMqtt: Message END"; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " WsMqtt: Message END"; buffer.insert(buffer.end(), data.begin(), data.end()); size += data.size(); @@ -144,19 +145,19 @@ namespace iot::mqtt { template void SubProtocol::onMessageError(uint16_t errnum) { - LOG(ERROR) << getSocketConnection()->getConnectionName() << " WsMqtt: Message error: " << errnum; + snode::semantic::appLog().error() << getSocketConnection()->getConnectionName() << " WsMqtt: Message error: " << errnum; } template void SubProtocol::onDisconnected() { iot::mqtt::MqttContext::onDisconnected(); - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WsMqtt: disconnected"; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " WsMqtt: disconnected"; } template bool SubProtocol::onSignal(int sig) { bool ret = iot::mqtt::MqttContext::onSignal(sig); - LOG(INFO) << getSocketConnection()->getConnectionName() << " WsMqtt: exit due to signal SIG" << utils::system::sigabbrev_np(sig) + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " WsMqtt: exit due to signal SIG" << utils::system::sigabbrev_np(sig) << " (" << sig << ")"; this->sendClose(); diff --git a/src/iot/mqtt/client/Mqtt.cpp b/src/iot/mqtt/client/Mqtt.cpp index 2db5317d98..eed4f7d2ad 100644 --- a/src/iot/mqtt/client/Mqtt.cpp +++ b/src/iot/mqtt/client/Mqtt.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -90,9 +91,9 @@ namespace iot::mqtt::client { session.fromJson(sessionStoreJson); - LOG(DEBUG) << connectionName << " MQTT Client: ... Persistent session data loaded successful"; + snode::semantic::appLog().debug() << connectionName << " MQTT Client: ... Persistent session data loaded successful"; } catch (const nlohmann::json::exception&) { - LOG(DEBUG) << connectionName << " MQTT Client: ... Starting with empty session: Session store '" + snode::semantic::appLog().debug() << connectionName << " MQTT Client: ... Starting with empty session: Session store '" << sessionStoreFileName << "' empty or corrupted"; session.clear(); @@ -101,12 +102,12 @@ namespace iot::mqtt::client { sessionStoreFile.close(); std::remove(sessionStoreFileName.data()); // NOLINT - LOG(INFO) << connectionName << " MQTT Client: Restoring saved session done"; + snode::semantic::appLog().info() << connectionName << " MQTT Client: Restoring saved session done"; } else { - PLOG(WARNING) << connectionName << " MQTT Client: ... Could not read session store '" << sessionStoreFileName << "'"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Warning, errno) << connectionName << " MQTT Client: ... Could not read session store '" << sessionStoreFileName << "'"; } } else { - LOG(INFO) << connectionName << " MQTT Client: Session not reloaded: Session store filename empty"; + snode::semantic::appLog().info() << connectionName << " MQTT Client: Session not reloaded: Session store filename empty"; } } @@ -123,10 +124,10 @@ namespace iot::mqtt::client { sessionStoreFile.close(); } else { - PLOG(DEBUG) << connectionName << " MQTT Client: Could not write session store '" << sessionStoreFileName << "'"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Debug, errno) << connectionName << " MQTT Client: Could not write session store '" << sessionStoreFileName << "'"; } } else { - LOG(INFO) << connectionName << " MQTT Client: Session not saved: Session store filename empty"; + snode::semantic::appLog().info() << connectionName << " MQTT Client: Session not saved: Session store filename empty"; } pingTimer.cancel(); @@ -192,12 +193,12 @@ namespace iot::mqtt::client { } void Mqtt::_onConnack(const iot::mqtt::client::packets::Connack& connack) { - LOG(INFO) << connectionName << " MQTT Client: Acknowledge Flag: " << static_cast(connack.getAcknowledgeFlags()); - LOG(INFO) << connectionName << " MQTT Client: Return code: " << static_cast(connack.getReturnCode()); - LOG(INFO) << connectionName << " MQTT Client: Session present: " << connack.getSessionPresent(); + snode::semantic::appLog().info() << connectionName << " MQTT Client: Acknowledge Flag: " << static_cast(connack.getAcknowledgeFlags()); + snode::semantic::appLog().info() << connectionName << " MQTT Client: Return code: " << static_cast(connack.getReturnCode()); + snode::semantic::appLog().info() << connectionName << " MQTT Client: Session present: " << connack.getSessionPresent(); if (connack.getReturnCode() != MQTT_CONNACK_ACCEPT) { - LOG(ERROR) << connectionName << " MQTT Client: Negative ack received"; + snode::semantic::appLog().error() << connectionName << " MQTT Client: Negative ack received"; } else { initSession(&session, keepAlive); @@ -219,10 +220,10 @@ namespace iot::mqtt::client { void Mqtt::_onSuback(const iot::mqtt::client::packets::Suback& suback) { if (suback.getPacketIdentifier() == 0) { - LOG(ERROR) << connectionName << " MQTT Client: PackageIdentifier missing"; + snode::semantic::appLog().error() << connectionName << " MQTT Client: PackageIdentifier missing"; mqttContext->close(); } else { - LOG(DEBUG) << connectionName << " MQTT Client: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) + snode::semantic::appLog().debug() << connectionName << " MQTT Client: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << suback.getPacketIdentifier() << std::dec; std::stringstream ss; @@ -237,7 +238,7 @@ namespace iot::mqtt::client { ss << "0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(returnCode) << " "; // << " | "; } - LOG(DEBUG) << connectionName << " MQTT Client: Return codes: " << ss.str(); + snode::semantic::appLog().debug() << connectionName << " MQTT Client: Return codes: " << ss.str(); onSuback(suback); } @@ -245,10 +246,10 @@ namespace iot::mqtt::client { void Mqtt::_onUnsuback(const iot::mqtt::client::packets::Unsuback& unsuback) { if (unsuback.getPacketIdentifier() == 0) { - LOG(ERROR) << connectionName << " MQTT Client: PacketIdentifier missing"; + snode::semantic::appLog().error() << connectionName << " MQTT Client: PacketIdentifier missing"; mqttContext->close(); } else { - LOG(DEBUG) << connectionName << " MQTT Client: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) + snode::semantic::appLog().debug() << connectionName << " MQTT Client: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << unsuback.getPacketIdentifier() << std::dec; onUnsuback(unsuback); @@ -271,7 +272,7 @@ namespace iot::mqtt::client { const std::string& username, const std::string& password, bool loopPrevention) const { // Client - LOG(INFO) << connectionName << " MQTT Client: CONNECT send: " << clientId; + snode::semantic::appLog().info() << connectionName << " MQTT Client: CONNECT send: " << clientId; send(iot::mqtt::packets::Connect( clientId, keepAlive, cleanSession, willTopic, willMessage, willQoS, willRetain, username, password, loopPrevention)); @@ -279,7 +280,7 @@ namespace iot::mqtt::client { void Mqtt::sendSubscribe(const std::list& topics) const { // Client for (const iot::mqtt::Topic& topic : topics) { - LOG(INFO) << connectionName << " MQTT Client: SUBSCRIBE with qos=" << static_cast(topic.getQoS()) << " for " + snode::semantic::appLog().info() << connectionName << " MQTT Client: SUBSCRIBE with qos=" << static_cast(topic.getQoS()) << " for " << topic.getName(); } @@ -290,7 +291,7 @@ namespace iot::mqtt::client { void Mqtt::sendUnsubscribe(const std::list& topics) const { // Client for (const std::string& topic : topics) { - LOG(INFO) << connectionName << " MQTT Client: UNSUBSCRIBE from " << topic; + snode::semantic::appLog().info() << connectionName << " MQTT Client: UNSUBSCRIBE from " << topic; } if (!topics.empty()) { diff --git a/src/iot/mqtt/server/Mqtt.cpp b/src/iot/mqtt/server/Mqtt.cpp index 5cb167815b..dff4e58075 100644 --- a/src/iot/mqtt/server/Mqtt.cpp +++ b/src/iot/mqtt/server/Mqtt.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -147,30 +148,30 @@ namespace iot::mqtt::server { bool success = true; if (broker->hasActiveSession(clientId)) { - LOG(ERROR) << connectionName << " MQTT Broker: Existing session found for ClientId = " << clientId; - LOG(ERROR) << connectionName << " MQTT Broker: closing"; + snode::semantic::appLog().error() << connectionName << " MQTT Broker: Existing session found for ClientId = " << clientId; + snode::semantic::appLog().error() << connectionName << " MQTT Broker: closing"; sendConnack(MQTT_CONNACK_IDENTIFIERREJECTED, 0); willFlag = false; success = false; } else if (broker->hasRetainedSession(clientId)) { - LOG(INFO) << connectionName << " MQTT Broker: Retained session found for ClientId = " << clientId; + snode::semantic::appLog().info() << connectionName << " MQTT Broker: Retained session found for ClientId = " << clientId; if (cleanSession) { - LOG(DEBUG) << connectionName << " New SessionId = " << this; + snode::semantic::appLog().debug() << connectionName << " New SessionId = " << this; sendConnack(MQTT_CONNACK_ACCEPT, MQTT_SESSION_NEW); broker->unsubscribe(clientId); initSession(broker->newSession(clientId, this), keepAlive); } else { - LOG(DEBUG) << connectionName << " Renew SessionId = " << this; + snode::semantic::appLog().debug() << connectionName << " Renew SessionId = " << this; sendConnack(MQTT_CONNACK_ACCEPT, MQTT_SESSION_PRESENT); initSession(broker->renewSession(clientId, this), keepAlive); broker->restartSession(clientId); } } else { - LOG(INFO) << connectionName << " MQTT Broker: No session found for ClientId = " << clientId; - LOG(INFO) << connectionName << " MQTT Broker: new SessionId = " << this; + snode::semantic::appLog().info() << connectionName << " MQTT Broker: No session found for ClientId = " << clientId; + snode::semantic::appLog().info() << connectionName << " MQTT Broker: new SessionId = " << this; sendConnack(MQTT_CONNACK_ACCEPT, MQTT_SESSION_NEW); @@ -183,12 +184,12 @@ namespace iot::mqtt::server { void Mqtt::releaseSession() { if (broker->isActiveSession(clientId, this)) { if (cleanSession) { - LOG(DEBUG) << connectionName << " MQTT Broker: Delete session for ClientId = " << clientId; - LOG(DEBUG) << connectionName << " MQTT Broker: SessionId = " << this; + snode::semantic::appLog().debug() << connectionName << " MQTT Broker: Delete session for ClientId = " << clientId; + snode::semantic::appLog().debug() << connectionName << " MQTT Broker: SessionId = " << this; broker->deleteSession(clientId); } else { - LOG(DEBUG) << connectionName << " MQTT Broker: Retain session for ClientId = " << clientId; - LOG(DEBUG) << connectionName << " MQTT Broker: SessionId = " << this; + snode::semantic::appLog().debug() << connectionName << " MQTT Broker: Retain session for ClientId = " << clientId; + snode::semantic::appLog().debug() << connectionName << " MQTT Broker: SessionId = " << this; broker->retainSession(clientId); } } @@ -216,50 +217,50 @@ namespace iot::mqtt::server { } void Mqtt::_onConnect(const iot::mqtt::server::packets::Connect& connect) { - LOG(INFO) << connectionName << " MQTT Broker: Protocol: " << connect.getProtocol(); - LOG(INFO) << connectionName << " MQTT Broker: Version: " << static_cast(connect.getLevel()); - LOG(INFO) << connectionName << " MQTT Broker: ConnectFlags: 0x" << std::hex << std::setfill('0') << std::setw(2) + snode::semantic::appLog().info() << connectionName << " MQTT Broker: Protocol: " << connect.getProtocol(); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: Version: " << static_cast(connect.getLevel()); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: ConnectFlags: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(connect.getConnectFlags()) << std::dec << std::setw(0); - LOG(INFO) << connectionName << " MQTT Broker: KeepAlive: " << connect.getKeepAlive(); - LOG(INFO) << connectionName << " MQTT Broker: ClientID: " << connect.getClientId(); - LOG(INFO) << connectionName << " MQTT Broker: CleanSession: " << connect.getCleanSession(); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: KeepAlive: " << connect.getKeepAlive(); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: ClientID: " << connect.getClientId(); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: CleanSession: " << connect.getCleanSession(); if (connect.getWillFlag()) { - LOG(INFO) << connectionName << " MQTT Broker: WillTopic: " << connect.getWillTopic(); - LOG(INFO) << connectionName << " MQTT Broker: WillMessage: " << connect.getWillMessage(); - LOG(INFO) << connectionName << " MQTT Broker: WillQoS: " << static_cast(connect.getWillQoS()); - LOG(INFO) << connectionName << " MQTT Broker: WillRetain: " << connect.getWillRetain(); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: WillTopic: " << connect.getWillTopic(); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: WillMessage: " << connect.getWillMessage(); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: WillQoS: " << static_cast(connect.getWillQoS()); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: WillRetain: " << connect.getWillRetain(); } if (connect.getUsernameFlag()) { - LOG(INFO) << connectionName << " MQTT Broker: Username: " << connect.getUsername(); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: Username: " << connect.getUsername(); } if (connect.getPasswordFlag()) { - LOG(INFO) << connectionName << " MQTT Broker: Password: " << connect.getPassword(); + snode::semantic::appLog().info() << connectionName << " MQTT Broker: Password: " << connect.getPassword(); } if (connect.getProtocol() != "MQTT") { - LOG(ERROR) << connectionName << " MQTT Broker: Wrong Protocol: " << connect.getProtocol(); + snode::semantic::appLog().error() << connectionName << " MQTT Broker: Wrong Protocol: " << connect.getProtocol(); mqttContext->close(); } else if ((connect.getLevel()) != MQTT_VERSION_3_1_1) { - LOG(ERROR) << connectionName << " MQTT Broker: Wrong Protocol Level: " << MQTT_VERSION_3_1_1 << " != " << connect.getLevel(); + snode::semantic::appLog().error() << connectionName << " MQTT Broker: Wrong Protocol Level: " << MQTT_VERSION_3_1_1 << " != " << connect.getLevel(); sendConnack(MQTT_CONNACK_UNACEPTABLEVERSION, MQTT_SESSION_NEW); mqttContext->close(); } else if (connect.isFakedClientId() && !connect.getCleanSession()) { - LOG(ERROR) << connectionName << " MQTT Broker: Resume session but no ClientId present"; + snode::semantic::appLog().error() << connectionName << " MQTT Broker: Resume session but no ClientId present"; sendConnack(MQTT_CONNACK_IDENTIFIERREJECTED, MQTT_SESSION_NEW); mqttContext->close(); } else if (!connect.getWillFlag() && (connect.getWillQoS() != 0 || connect.getWillRetain())) { - LOG(ERROR) << connectionName << " MQTT Broker: WillFlag not set but WillQoS or WillRetain set"; + snode::semantic::appLog().error() << connectionName << " MQTT Broker: WillFlag not set but WillQoS or WillRetain set"; mqttContext->close(); } else if (connect.getWillQoS() > 2) { - LOG(ERROR) << connectionName << " MQTT Broker: WillQoS larger than 2"; + snode::semantic::appLog().error() << connectionName << " MQTT Broker: WillQoS larger than 2"; mqttContext->close(); } else if (connect.getPasswordFlag() && !connect.getUsernameFlag()) { - LOG(ERROR) << connectionName << " MQTT Broker: Password flag set but username flag not"; + snode::semantic::appLog().error() << connectionName << " MQTT Broker: Password flag set but username flag not"; mqttContext->close(); } else { @@ -301,14 +302,14 @@ namespace iot::mqtt::server { void Mqtt::_onSubscribe(const iot::mqtt::server::packets::Subscribe& subscribe) { if (subscribe.getPacketIdentifier() == 0) { - LOG(ERROR) << connectionName << " MQTT Broker: PackageIdentifier missing"; + snode::semantic::appLog().error() << connectionName << " MQTT Broker: PackageIdentifier missing"; mqttContext->close(); } else { - LOG(DEBUG) << connectionName << " MQTT Broker: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) + snode::semantic::appLog().debug() << connectionName << " MQTT Broker: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << subscribe.getPacketIdentifier() << std::dec; for (const iot::mqtt::Topic& topic : subscribe.getTopics()) { - LOG(INFO) << connectionName << " MQTT Broker: Topic filter: '" << topic.getName() + snode::semantic::appLog().info() << connectionName << " MQTT Broker: Topic filter: '" << topic.getName() << "', QoS: " << static_cast(topic.getQoS()); } @@ -326,14 +327,14 @@ namespace iot::mqtt::server { void Mqtt::_onUnsubscribe(const iot::mqtt::server::packets::Unsubscribe& unsubscribe) { if (unsubscribe.getPacketIdentifier() == 0) { - LOG(ERROR) << connectionName << " MQTT Broker: PackageIdentifier missing"; + snode::semantic::appLog().error() << connectionName << " MQTT Broker: PackageIdentifier missing"; mqttContext->close(); } else { - LOG(DEBUG) << connectionName << " MQTT Broker: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) + snode::semantic::appLog().debug() << connectionName << " MQTT Broker: PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << unsubscribe.getPacketIdentifier() << std::dec; for (const std::string& topic : unsubscribe.getTopics()) { - LOG(INFO) << connectionName << " MQTT Broker: Topic: " << topic; + snode::semantic::appLog().info() << connectionName << " MQTT Broker: Topic: " << topic; } for (const std::string& topic : unsubscribe.getTopics()) { diff --git a/src/iot/mqtt/server/broker/Broker.cpp b/src/iot/mqtt/server/broker/Broker.cpp index 69070488b4..c5215ec17c 100644 --- a/src/iot/mqtt/server/broker/Broker.cpp +++ b/src/iot/mqtt/server/broker/Broker.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -77,9 +78,9 @@ namespace iot::mqtt::server::broker { retainTree.fromJson(sessionStoreJson["retain_tree"]); subscriptionTree.fromJson(sessionStoreJson["subscription_tree"]); - LOG(INFO) << "MQTT Broker: Persistent session data loaded successful"; + snode::semantic::appLog().info() << "MQTT Broker: Persistent session data loaded successful"; } catch (const nlohmann::json::exception&) { - LOG(INFO) << "MQTT Broker: Starting with empty session: Session store '" << sessionStoreFileName + snode::semantic::appLog().info() << "MQTT Broker: Starting with empty session: Session store '" << sessionStoreFileName << "' empty or corrupted"; sessionStore.clear(); @@ -90,12 +91,12 @@ namespace iot::mqtt::server::broker { sessionStoreFile.close(); std::remove(sessionStoreFileName.data()); // NOLINT - LOG(INFO) << "MQTT Broker: Restoring saved session done"; + snode::semantic::appLog().info() << "MQTT Broker: Restoring saved session done"; } else { - PLOG(WARNING) << "MQTT Broker: Could not read session store '" << sessionStoreFileName << "'"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Warning, errno) << "MQTT Broker: Could not read session store '" << sessionStoreFileName << "'"; } } else { - LOG(INFO) << "MQTT Broker: Session not reloaded: Session store filename empty"; + snode::semantic::appLog().info() << "MQTT Broker: Session not reloaded: Session store filename empty"; } } @@ -128,12 +129,12 @@ namespace iot::mqtt::server::broker { sessionStoreFile.close(); - LOG(INFO) << "MQTT Broker: Session store written '" << sessionStoreFileName << "'"; + snode::semantic::appLog().info() << "MQTT Broker: Session store written '" << sessionStoreFileName << "'"; } else { - PLOG(ERROR) << "MQTT Broker: Could not write session store '" << sessionStoreFileName << "'"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "MQTT Broker: Could not write session store '" << sessionStoreFileName << "'"; } } else { - LOG(INFO) << "MQTT Broker: Session not saved: Session store filename empty"; + snode::semantic::appLog().info() << "MQTT Broker: Session not saved: Session store filename empty"; } } @@ -163,10 +164,10 @@ namespace iot::mqtt::server::broker { } void Broker::restartSession(const std::string& clientId) { - LOG(INFO) << "MQTT Broker: Retained: Send PUBLISH: " << clientId; + snode::semantic::appLog().info() << "MQTT Broker: Retained: Send PUBLISH: " << clientId; subscriptionTree.appear(clientId); - LOG(INFO) << "MQTT Broker: Queued: Send PUBLISH: " << clientId; + snode::semantic::appLog().info() << "MQTT Broker: Queued: Send PUBLISH: " << clientId; sessionStore[clientId].publishQueued(); } @@ -235,7 +236,7 @@ namespace iot::mqtt::server::broker { } void Broker::sendPublish(const std::string& clientId, Message& message, uint8_t qoS, bool retain) { - LOG(INFO) << "MQTT Broker: Send PUBLISH: " << clientId; + snode::semantic::appLog().info() << "MQTT Broker: Send PUBLISH: " << clientId; sessionStore[clientId].sendPublish(message, qoS, retain); } diff --git a/src/iot/mqtt/server/broker/RetainTree.cpp b/src/iot/mqtt/server/broker/RetainTree.cpp index 57ada93cb5..eda4ebf6d3 100644 --- a/src/iot/mqtt/server/broker/RetainTree.cpp +++ b/src/iot/mqtt/server/broker/RetainTree.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -117,10 +118,10 @@ namespace iot::mqtt::server::broker { } void RetainTree::TopicLevel::retain(const Message& message, std::string topic) { if (topic.empty()) { - LOG(DEBUG) << "MQTT Broker: Retain:"; - LOG(DEBUG) << "MQTT Broker: Topic: " << message.getTopic(); - LOG(DEBUG) << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); - LOG(DEBUG) << "MQTT Broker: QoS: " << static_cast(message.getQoS()); + snode::semantic::appLog().debug() << "MQTT Broker: Retain:"; + snode::semantic::appLog().debug() << "MQTT Broker: Topic: " << message.getTopic(); + snode::semantic::appLog().debug() << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); + snode::semantic::appLog().debug() << "MQTT Broker: QoS: " << static_cast(message.getQoS()); this->message = message; } else { @@ -134,8 +135,8 @@ namespace iot::mqtt::server::broker { bool RetainTree::TopicLevel::release(std::string topic) { if (topic.empty()) { - LOG(DEBUG) << "MQTT Broker: Release retained:"; - LOG(DEBUG) << "MQTT Broker: Topic: " << message.getTopic(); + snode::semantic::appLog().debug() << "MQTT Broker: Release retained:"; + snode::semantic::appLog().debug() << "MQTT Broker: Topic: " << message.getTopic(); message = Message(); } else { @@ -146,7 +147,7 @@ namespace iot::mqtt::server::broker { topic.erase(0, topicLevel.size() + 1); if (it->second.release(topic)) { - LOG(DEBUG) << " Erase: " << topicLevel; + snode::semantic::appLog().debug() << " Erase: " << topicLevel; subTopicLevels.erase(it); } @@ -159,16 +160,16 @@ namespace iot::mqtt::server::broker { void RetainTree::TopicLevel::appear(const std::string& clientId, std::string topic, uint8_t qoS) { if (topic.empty()) { if (!message.getTopic().empty()) { - LOG(INFO) << "MQTT Broker: Retained Topic found:"; - LOG(INFO) << "MQTT Broker: Topic: " << message.getTopic(); - LOG(INFO) << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); - LOG(DEBUG) << "MQTT Broker: QoS: " << static_cast(message.getQoS()); - LOG(DEBUG) << "MQTT Broker: Client:"; - LOG(DEBUG) << "MQTT Broker: QoS: " << static_cast(qoS); - - LOG(INFO) << "MQTT Broker: Distributing message ..."; + snode::semantic::appLog().info() << "MQTT Broker: Retained Topic found:"; + snode::semantic::appLog().info() << "MQTT Broker: Topic: " << message.getTopic(); + snode::semantic::appLog().info() << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); + snode::semantic::appLog().debug() << "MQTT Broker: QoS: " << static_cast(message.getQoS()); + snode::semantic::appLog().debug() << "MQTT Broker: Client:"; + snode::semantic::appLog().debug() << "MQTT Broker: QoS: " << static_cast(qoS); + + snode::semantic::appLog().info() << "MQTT Broker: Distributing message ..."; broker->sendPublish(clientId, message, std::min(message.getQoS(), qoS), true); - LOG(INFO) << "MQTT Broker: ... distributing message completed"; + snode::semantic::appLog().info() << "MQTT Broker: ... distributing message completed"; } } else { const std::string topicLevel = topic.substr(0, topic.find('/')); @@ -194,16 +195,16 @@ namespace iot::mqtt::server::broker { void RetainTree::TopicLevel::appear(const std::string& clientId, uint8_t clientQoS) { if (!message.getTopic().empty()) { - LOG(INFO) << "MQTT Broker: Retained Topic found:"; - LOG(INFO) << "MQTT Broker: Topic: " << message.getTopic(); - LOG(INFO) << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); - LOG(DEBUG) << "MQTT Broker: QoS: " << static_cast(message.getQoS()); - LOG(DEBUG) << "MQTT Broker: Client:"; - LOG(DEBUG) << "MQTT Broker: QoS: " << static_cast(clientQoS); - - LOG(INFO) << "MQTT Broker: Distributing message ..."; + snode::semantic::appLog().info() << "MQTT Broker: Retained Topic found:"; + snode::semantic::appLog().info() << "MQTT Broker: Topic: " << message.getTopic(); + snode::semantic::appLog().info() << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); + snode::semantic::appLog().debug() << "MQTT Broker: QoS: " << static_cast(message.getQoS()); + snode::semantic::appLog().debug() << "MQTT Broker: Client:"; + snode::semantic::appLog().debug() << "MQTT Broker: QoS: " << static_cast(clientQoS); + + snode::semantic::appLog().info() << "MQTT Broker: Distributing message ..."; broker->sendPublish(clientId, message, std::min(message.getQoS(), clientQoS), true); - LOG(INFO) << "MQTT Broker: ... distributing message completed"; + snode::semantic::appLog().info() << "MQTT Broker: ... distributing message completed"; } for (auto& [topicLevel, subTopicLevel] : subTopicLevels) { diff --git a/src/iot/mqtt/server/broker/Session.cpp b/src/iot/mqtt/server/broker/Session.cpp index 4e1e9a8239..a2f5061eb2 100644 --- a/src/iot/mqtt/server/broker/Session.cpp +++ b/src/iot/mqtt/server/broker/Session.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -64,13 +65,13 @@ namespace iot::mqtt::server::broker { } void Session::sendPublish(Message& message, uint8_t qoS, bool retain) { - LOG(INFO) << "MQTT Broker: TopicName: " << message.getTopic(); - LOG(INFO) << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); - LOG(DEBUG) << "MQTT Broker: QoS: " << static_cast(std::min(qoS, message.getQoS())); + snode::semantic::appLog().info() << "MQTT Broker: TopicName: " << message.getTopic(); + snode::semantic::appLog().info() << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); + snode::semantic::appLog().debug() << "MQTT Broker: QoS: " << static_cast(std::min(qoS, message.getQoS())); if (isActive()) { - LOG(DEBUG) << "MQTT Broker: ClientId: " << mqtt->getClientId(); - LOG(DEBUG) << "MQTT Broker: OriginClientId: " << message.getOriginClientId(); + snode::semantic::appLog().debug() << "MQTT Broker: ClientId: " << mqtt->getClientId(); + snode::semantic::appLog().debug() << "MQTT Broker: OriginClientId: " << message.getOriginClientId(); if ((mqtt->getReflect() || mqtt->getClientId() != message.getOriginClientId())) { mqtt->sendPublish(message.getTopic(), @@ -78,7 +79,7 @@ namespace iot::mqtt::server::broker { std::min(message.getQoS(), qoS), !mqtt->getReflect() ? message.getOriginRetain() || retain : retain); } else { - LOG(INFO) << "MQTT Broker: Suppress reflection to origin to avoid message looping"; + snode::semantic::appLog().info() << "MQTT Broker: Suppress reflection to origin to avoid message looping"; } } else { // Offline session behavior: @@ -89,17 +90,17 @@ namespace iot::mqtt::server::broker { message.setQoS(effectiveQoS); messageQueue.emplace_back(message); } else { - LOG(INFO) << "MQTT Broker: Drop QoS0 message for inactive session"; + snode::semantic::appLog().info() << "MQTT Broker: Drop QoS0 message for inactive session"; } } } void Session::publishQueued() { - LOG(INFO) << "MQTT Broker: send queued messages ..."; + snode::semantic::appLog().info() << "MQTT Broker: send queued messages ..."; for (iot::mqtt::server::broker::Message& message : messageQueue) { sendPublish(message, message.getQoS(), false); } - LOG(INFO) << "MQTT Broker: ... done"; + snode::semantic::appLog().info() << "MQTT Broker: ... done"; messageQueue.clear(); } diff --git a/src/iot/mqtt/server/broker/SubscriptionTree.cpp b/src/iot/mqtt/server/broker/SubscriptionTree.cpp index 466b997650..cd687f9efe 100644 --- a/src/iot/mqtt/server/broker/SubscriptionTree.cpp +++ b/src/iot/mqtt/server/broker/SubscriptionTree.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -75,7 +76,7 @@ namespace iot::mqtt::server::broker { success = true; } else { - LOG(ERROR) << "MQTT Broker: Subscribe: Wrong '#' placement: " << topic; + snode::semantic::appLog().error() << "MQTT Broker: Subscribe: Wrong '#' placement: " << topic; } return success; @@ -86,7 +87,7 @@ namespace iot::mqtt::server::broker { if (!message.getTopic().empty() && (hashCount == 0 || (hashCount == 1 && message.getTopic().ends_with('#')))) { head.publish(message, message.getTopic()); } else { - LOG(ERROR) << "MQTT Broker: Publish: Wrong '#' placement: " << message.getTopic(); + snode::semantic::appLog().error() << "MQTT Broker: Publish: Wrong '#' placement: " << message.getTopic(); } } @@ -95,7 +96,7 @@ namespace iot::mqtt::server::broker { if (!topic.empty() && (hashCount == 0 || (hashCount == 1 && topic.ends_with('#')))) { head.unsubscribe(clientId, topic); } else { - LOG(ERROR) << "MQTT Broker: Unsubscribe: Wrong '#' placement: " << topic; + snode::semantic::appLog().error() << "MQTT Broker: Unsubscribe: Wrong '#' placement: " << topic; } } @@ -142,8 +143,8 @@ namespace iot::mqtt::server::broker { bool SubscriptionTree::TopicLevel::subscribe(const std::string& clientId, uint8_t qoS, std::string topic) { if (topic.empty()) { - LOG(INFO) << "MQTT Broker: Subscribe"; - LOG(INFO) << "MQTT Broker: ClientId: " << clientId; + snode::semantic::appLog().info() << "MQTT Broker: Subscribe"; + snode::semantic::appLog().info() << "MQTT Broker: ClientId: " << clientId; clientIds[clientId] = qoS; } else { @@ -154,11 +155,11 @@ namespace iot::mqtt::server::broker { const auto& [it, inserted] = topicLevels.insert({topicLevel, SubscriptionTree::TopicLevel(broker, topicLevel)}); if (!it->second.subscribe(clientId, qoS, topic)) { - LOG(DEBUG) << "MQTT Broker: Erase topic: " << topicLevel << " /" << topic; + snode::semantic::appLog().debug() << "MQTT Broker: Erase topic: " << topicLevel << " /" << topic; topicLevels.erase(it); } else { - LOG(INFO) << "MQTT Broker: Topic: " << topicLevel << " /" << topic; + snode::semantic::appLog().info() << "MQTT Broker: Topic: " << topicLevel << " /" << topic; } } @@ -167,27 +168,27 @@ namespace iot::mqtt::server::broker { void SubscriptionTree::TopicLevel::publish(Message& message, std::string topic) { if (topic.empty()) { - LOG(INFO) << "MQTT Broker: Found match:"; - LOG(INFO) << "MQTT Broker: Topic: '" << message.getTopic() << "';"; - LOG(INFO) << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); + snode::semantic::appLog().info() << "MQTT Broker: Found match:"; + snode::semantic::appLog().info() << "MQTT Broker: Topic: '" << message.getTopic() << "';"; + snode::semantic::appLog().info() << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); - LOG(INFO) << "MQTT Broker: Distribute PUBLISH for match ..."; + snode::semantic::appLog().info() << "MQTT Broker: Distribute PUBLISH for match ..."; for (auto& [clientId, clientQoS] : clientIds) { broker->sendPublish(clientId, message, clientQoS, false); } - LOG(INFO) << "MQTT Broker: ... distributing PUBLISH for match completed"; + snode::semantic::appLog().info() << "MQTT Broker: ... distributing PUBLISH for match completed"; const auto nextHashLevel = topicLevels.find("#"); if (nextHashLevel != topicLevels.end()) { - LOG(INFO) << "MQTT Broker: Found parent match:"; - LOG(INFO) << "MQTT Broker: Topic: '" << message.getTopic() << "'"; - LOG(INFO) << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); + snode::semantic::appLog().info() << "MQTT Broker: Found parent match:"; + snode::semantic::appLog().info() << "MQTT Broker: Topic: '" << message.getTopic() << "'"; + snode::semantic::appLog().info() << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); - LOG(INFO) << "MQTT Broker: Distribute PUBLISH for match ..."; + snode::semantic::appLog().info() << "MQTT Broker: Distribute PUBLISH for match ..."; for (auto& [clientId, clientQoS] : nextHashLevel->second.clientIds) { broker->sendPublish(clientId, message, clientQoS, false); } - LOG(INFO) << "MQTT Broker: ... distributing PUBLISH for match completed"; + snode::semantic::appLog().info() << "MQTT Broker: ... distributing PUBLISH for match completed"; } } else { const std::string topicLevel = topic.substr(0, topic.find('/')); @@ -206,15 +207,15 @@ namespace iot::mqtt::server::broker { foundNode = topicLevels.find("#"); if (foundNode != topicLevels.end()) { - LOG(INFO) << "MQTT Broker: Found match:"; - LOG(INFO) << "MQTT Broker: Topic: '" << message.getTopic() << "'"; - LOG(INFO) << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); + snode::semantic::appLog().info() << "MQTT Broker: Found match:"; + snode::semantic::appLog().info() << "MQTT Broker: Topic: '" << message.getTopic() << "'"; + snode::semantic::appLog().info() << "MQTT Broker: Message:\n" << iot::mqtt::Mqtt::toHexString(message.getMessage()); - LOG(INFO) << "MQTT Broker: Distribute PUBLISH for match '" << message.getTopic() << "' ..."; + snode::semantic::appLog().info() << "MQTT Broker: Distribute PUBLISH for match '" << message.getTopic() << "' ..."; for (auto& [clientId, clientQoS] : foundNode->second.clientIds) { broker->sendPublish(clientId, message, clientQoS, false); } - LOG(INFO) << "MQTT Broker: ... distributing PUBLISH for match completed"; + snode::semantic::appLog().info() << "MQTT Broker: ... distributing PUBLISH for match completed"; } } } @@ -222,9 +223,9 @@ namespace iot::mqtt::server::broker { bool SubscriptionTree::TopicLevel::unsubscribe(const std::string& clientId, std::string topic) { if (topic.empty()) { if (clientIds.erase(clientId) != 0) { - LOG(INFO) << "MQTT Broker: Unsubscribe"; - LOG(INFO) << "MQTT Broker: ClientId: " << clientId; - LOG(INFO) << "MQTT Broker: Topic: " << topicLevel; + snode::semantic::appLog().info() << "MQTT Broker: Unsubscribe"; + snode::semantic::appLog().info() << "MQTT Broker: ClientId: " << clientId; + snode::semantic::appLog().info() << "MQTT Broker: Topic: " << topicLevel; } } else { const std::string topicLevel = topic.substr(0, topic.find('/')); @@ -234,7 +235,7 @@ namespace iot::mqtt::server::broker { topic.erase(0, topicLevel.size() + 1); if (it->second.unsubscribe(clientId, topic)) { - LOG(DEBUG) << "MQTT Broker: Erase Topic: " << it->first; + snode::semantic::appLog().debug() << "MQTT Broker: Erase Topic: " << it->first; topicLevels.erase(it); } @@ -246,14 +247,14 @@ namespace iot::mqtt::server::broker { bool SubscriptionTree::TopicLevel::unsubscribe(const std::string& clientId) { if (clientIds.erase(clientId) != 0) { - LOG(INFO) << "MQTT Broker: Unsubscribe"; - LOG(INFO) << "MQTT Broker: ClientId: " << clientId; - LOG(INFO) << "MQTT Broker: Topic: " << topicLevel; + snode::semantic::appLog().info() << "MQTT Broker: Unsubscribe"; + snode::semantic::appLog().info() << "MQTT Broker: ClientId: " << clientId; + snode::semantic::appLog().info() << "MQTT Broker: Topic: " << topicLevel; } for (auto it = topicLevels.begin(); it != topicLevels.end();) { if (it->second.unsubscribe(clientId)) { - LOG(DEBUG) << "MQTT Broker: Erase Topic: " << it->first; + snode::semantic::appLog().debug() << "MQTT Broker: Erase Topic: " << it->first; it = topicLevels.erase(it); } else { diff --git a/src/log/CMakeLists.txt b/src/log/CMakeLists.txt index be1da04b48..4e9ee63b92 100644 --- a/src/log/CMakeLists.txt +++ b/src/log/CMakeLists.txt @@ -110,4 +110,10 @@ install( NAMESPACE snodec:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/snodec COMPONENT logger + +install( + FILES "${CMAKE_CURRENT_SOURCE_DIR}/../SemanticLog.h" + DESTINATION include/snode.c + COMPONENT logger +) ) diff --git a/src/log/Logger.h b/src/log/Logger.h index df71dfe61f..ae277579a3 100644 --- a/src/log/Logger.h +++ b/src/log/Logger.h @@ -124,6 +124,17 @@ namespace logger { std::ostringstream& stream(); + template + LogMessage& operator<<(const Value& value) { + message << value; + return *this; + } + + LogMessage& operator<<(std::ostream& (*manipulator)(std::ostream&)) { + message << manipulator; + return *this; + } + private: Level level; int verboseLevel; @@ -135,36 +146,4 @@ namespace logger { } // namespace logger -#ifdef SNODEC_DISABLE_LOGLEVEL_LOGGING -#define LOG(level) \ - if (true) { \ - } else \ - ::logger::LogMessage(::logger::Level::level).stream() -#define PLOG(level) \ - if (true) { \ - } else \ - ::logger::LogMessage(::logger::Level::level, -1, true).stream() -#else -#define LOG(level) \ - if (!::logger::Logger::shouldLog(::logger::Level::level)) { \ - } else \ - ::logger::LogMessage(::logger::Level::level).stream() -#define PLOG(level) \ - if (!::logger::Logger::shouldLog(::logger::Level::level)) { \ - } else \ - ::logger::LogMessage(::logger::Level::level, -1, true).stream() -#endif - -#ifdef SNODEC_DISABLE_VERBOSE_LOGGING -#define VLOG(level) \ - if (true) { \ - } else \ - ::logger::LogMessage(::logger::Level::VERBOSE, level).stream() -#else -#define VLOG(level) \ - if (!::logger::Logger::shouldVerbose(level)) { \ - } else \ - ::logger::LogMessage(::logger::Level::VERBOSE, level).stream() -#endif - #endif // LOGGER_LOGGER_H diff --git a/src/net/config/ConfigPhysicalSocket.cpp b/src/net/config/ConfigPhysicalSocket.cpp index 5076b94f1f..9bd9bf972e 100644 --- a/src/net/config/ConfigPhysicalSocket.cpp +++ b/src/net/config/ConfigPhysicalSocket.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -83,7 +84,7 @@ namespace net::config { removeSocketOption(optLevel, optName); } } catch (CLI::OptionNotFound& err) { - LOG(ERROR) << err.what(); + snode::semantic::appLog().error() << err.what(); } }, description, diff --git a/src/net/config/stream/tls/ConfigSocketServer.hpp b/src/net/config/stream/tls/ConfigSocketServer.hpp index 1ebd457e58..fcbfe22c90 100644 --- a/src/net/config/stream/tls/ConfigSocketServer.hpp +++ b/src/net/config/stream/tls/ConfigSocketServer.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -100,7 +101,7 @@ namespace net::config::stream::tls { sniCtxMap.insert(sslSans.begin(), sslSans.end()); for (const auto& [sni, ctx] : sniCtxMap) { - LOG(TRACE) << getInstanceName() << " SSL/TLS: SSL_CTX (M) sni for '" << sni << "' from master certificate installed"; + snode::semantic::appLog().trace() << getInstanceName() << " SSL/TLS: SSL_CTX (M) sni for '" << sni << "' from master certificate installed"; } for (const auto& [domain, sniCertConf] : getSniCerts()) { @@ -137,21 +138,21 @@ namespace net::config::stream::tls { sniCtxs.push_back(newCtx); sniCtxMap.insert_or_assign(domain, newCtx); - LOG(TRACE) << getInstanceName() << " SSL/TLS: SSL_CTX (E) sni for '" << domain << "' explicitly installed"; + snode::semantic::appLog().trace() << getInstanceName() << " SSL/TLS: SSL_CTX (E) sni for '" << domain << "' explicitly installed"; for (const auto& [san, ctx] : core::socket::stream::tls::ssl_get_sans(newCtx)) { sniCtxMap.insert_or_assign(san, ctx); - LOG(TRACE) << getInstanceName() << " SSL/TLS: SSL_CTX (S) sni for '" << san << "' from SAN installed"; + snode::semantic::appLog().trace() << getInstanceName() << " SSL/TLS: SSL_CTX (S) sni for '" << san << "' from SAN installed"; } } else { - LOG(WARNING) << getInstanceName() << " SSL/TLS: Can not create SNI_SSL_CTX for domain '" << domain << "'"; + snode::semantic::appLog().warn() << getInstanceName() << " SSL/TLS: Can not create SNI_SSL_CTX for domain '" << domain << "'"; } } } - LOG(TRACE) << getInstanceName() << " SSL/TLS: SNI list result:"; + snode::semantic::appLog().trace() << getInstanceName() << " SSL/TLS: SNI list result:"; for (const auto& [sni, ctx] : sniCtxMap) { - LOG(TRACE) << " " << sni; + snode::semantic::appLog().trace() << " " << sni; } } @@ -160,21 +161,21 @@ namespace net::config::stream::tls { template SSL_CTX* ConfigSocketServer::getSniCtx(const std::string& serverNameIndication) { - LOG(TRACE) << getInstanceName() << " SSL/TLS SNI: Lookup for sni='" << serverNameIndication << "' in sni certificates"; + snode::semantic::appLog().trace() << getInstanceName() << " SSL/TLS SNI: Lookup for sni='" << serverNameIndication << "' in sni certificates"; SSL_CTX* sniCtx = nullptr; std::map::iterator sniPairIt = std::find_if( sniCtxMap.begin(), sniCtxMap.end(), [&serverNameIndication, this](const std::pair& sniPair) -> bool { - LOG(TRACE) << getInstanceName() << " SSL/TLS SNI: .. " << sniPair.first.c_str(); + snode::semantic::appLog().trace() << getInstanceName() << " SSL/TLS SNI: .. " << sniPair.first.c_str(); return core::socket::stream::tls::match(sniPair.first.c_str(), serverNameIndication.c_str()); }); if (sniPairIt != sniCtxMap.end()) { - LOG(TRACE) << getInstanceName() << " SSL/TLS SNI: found for " << serverNameIndication << " -> '" << sniPairIt->first << "'"; + snode::semantic::appLog().trace() << getInstanceName() << " SSL/TLS SNI: found for " << serverNameIndication << " -> '" << sniPairIt->first << "'"; sniCtx = sniPairIt->second; } else { - LOG(WARNING) << getInstanceName() << " SSL/TL SNI: not found for " << serverNameIndication; + snode::semantic::appLog().warn() << getInstanceName() << " SSL/TL SNI: not found for " << serverNameIndication; } return sniCtx; diff --git a/src/net/in/SocketAddrInfo.cpp b/src/net/in/SocketAddrInfo.cpp index 1977d3a646..75d68c2295 100644 --- a/src/net/in/SocketAddrInfo.cpp +++ b/src/net/in/SocketAddrInfo.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -133,7 +134,7 @@ namespace net::in { << " sin_addr: " << hostBfr << "\n" << " sin_port: " << servBfr; - LOG(TRACE) << formatted.str(); + snode::semantic::appLog().trace() << formatted.str(); } } diff --git a/src/net/in6/SocketAddrInfo.cpp b/src/net/in6/SocketAddrInfo.cpp index c5fa7efc11..ae76e43b64 100644 --- a/src/net/in6/SocketAddrInfo.cpp +++ b/src/net/in6/SocketAddrInfo.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -126,7 +127,7 @@ namespace net::in6 { << " sin_addr: " << hostBfr << "\n" << " sin_port: " << servBfr; - LOG(TRACE) << formatted.str(); + snode::semantic::appLog().trace() << formatted.str(); } } diff --git a/src/net/un/phy/PhysicalSocket.hpp b/src/net/un/phy/PhysicalSocket.hpp index efdad5b03c..60b8b4837d 100644 --- a/src/net/un/phy/PhysicalSocket.hpp +++ b/src/net/un/phy/PhysicalSocket.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -79,21 +80,21 @@ namespace net::un::phy { PhysicalSocket::~PhysicalSocket() { if (lockFd >= 0) { if (std::remove(Super::getBindAddress().getSunPath().data()) == 0) { - LOG(DEBUG) << "Remove sun path: " << Super::getBindAddress().getSunPath(); + snode::semantic::appLog().debug() << "Remove sun path: " << Super::getBindAddress().getSunPath(); } else { - PLOG(ERROR) << "Remove sun path: " << Super::getBindAddress().getSunPath(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "Remove sun path: " << Super::getBindAddress().getSunPath(); } if (core::system::flock(lockFd, LOCK_UN) == 0) { - LOG(DEBUG) << "Remove lock from file: " << Super::getBindAddress().getSunPath().append(".lock"); + snode::semantic::appLog().debug() << "Remove lock from file: " << Super::getBindAddress().getSunPath().append(".lock"); } else { - PLOG(ERROR) << "Remove lock from file: " << Super::getBindAddress().getSunPath().append(".lock"); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "Remove lock from file: " << Super::getBindAddress().getSunPath().append(".lock"); } if (std::remove(Super::bindAddress.getSunPath().append(".lock").data()) == 0) { - LOG(DEBUG) << "Remove lock file: " << Super::getBindAddress().getSunPath().append(".lock"); + snode::semantic::appLog().debug() << "Remove lock file: " << Super::getBindAddress().getSunPath().append(".lock"); } else { - PLOG(ERROR) << "Remove lock file: " << Super::getBindAddress().getSunPath().append(".lock"); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "Remove lock file: " << Super::getBindAddress().getSunPath().append(".lock"); } core::system::close(lockFd); @@ -105,24 +106,24 @@ namespace net::un::phy { int PhysicalSocket::bind(SocketAddress& bindAddress) { if (!bindAddress.getSunPath().empty() && !bindAddress.getSunPath().starts_with('\0')) { if ((lockFd = open(bindAddress.getSunPath().append(".lock").data(), O_RDONLY | O_CREAT, 0600)) >= 0) { - LOG(DEBUG) << "Opening lock file: " << bindAddress.getSunPath().append(".lock").data(); + snode::semantic::appLog().debug() << "Opening lock file: " << bindAddress.getSunPath().append(".lock").data(); if (core::system::flock(lockFd, LOCK_EX | LOCK_NB) == 0) { - LOG(DEBUG) << "Locking lock file: " << bindAddress.getSunPath().append(".lock").data(); + snode::semantic::appLog().debug() << "Locking lock file: " << bindAddress.getSunPath().append(".lock").data(); if (std::filesystem::exists(bindAddress.getSunPath().data())) { if (std::remove(bindAddress.getSunPath().data()) == 0) { - LOG(WARNING) << "Removed stalled sun_path: " << bindAddress.getSunPath().data(); + snode::semantic::appLog().warn() << "Removed stalled sun_path: " << bindAddress.getSunPath().data(); } else { - PLOG(ERROR) << "Removed stalled sun path: " << bindAddress.getSunPath().data(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "Removed stalled sun path: " << bindAddress.getSunPath().data(); } } } else { - PLOG(ERROR) << "Locking lock file " << bindAddress.getSunPath().append(".lock").data(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "Locking lock file " << bindAddress.getSunPath().append(".lock").data(); core::system::close(lockFd); lockFd = -1; } } else { - PLOG(ERROR) << "Opening lock file: " << bindAddress.getSunPath().append(".lock").data(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "Opening lock file: " << bindAddress.getSunPath().append(".lock").data(); } } diff --git a/src/web/http/MimeTypes.cpp b/src/web/http/MimeTypes.cpp index 886df0067c..36f5d9255c 100644 --- a/src/web/http/MimeTypes.cpp +++ b/src/web/http/MimeTypes.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -246,7 +247,7 @@ namespace web::http { MimeTypes::magic = magic_open(MAGIC_MIME); if (magic_load(magic, nullptr) != 0) { - LOG(DEBUG) << "HTTP: Cannot load magic database - " + std::string(magic_error(magic)); + snode::semantic::appLog().debug() << "HTTP: Cannot load magic database - " + std::string(magic_error(magic)); magic_close(magic); magic = nullptr; } diff --git a/src/web/http/SocketContextUpgradeFactorySelector.hpp b/src/web/http/SocketContextUpgradeFactorySelector.hpp index c9777bf828..2458173afb 100644 --- a/src/web/http/SocketContextUpgradeFactorySelector.hpp +++ b/src/web/http/SocketContextUpgradeFactorySelector.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication @@ -97,19 +98,19 @@ namespace web::http { if (socketContextUpgradeFactory != nullptr) { if (add(socketContextUpgradeFactory, handle)) { - LOG(TRACE) << "HTTP: SocketContextUpgradeFactory create success: " << socketContextUpgradeName; + snode::semantic::appLog().trace() << "HTTP: SocketContextUpgradeFactory create success: " << socketContextUpgradeName; } else { - LOG(TRACE) << "HTTP: SocketContextUpgradeFactory already existing: " << socketContextUpgradeName; + snode::semantic::appLog().trace() << "HTTP: SocketContextUpgradeFactory already existing: " << socketContextUpgradeName; delete socketContextUpgradeFactory; socketContextUpgradeFactory = nullptr; core::DynamicLoader::dlClose(handle); } } else { - LOG(ERROR) << "HTTP: SocketContextUpgradeFactory create failed: " << socketContextUpgradeName; + snode::semantic::appLog().error() << "HTTP: SocketContextUpgradeFactory create failed: " << socketContextUpgradeName; core::DynamicLoader::dlClose(handle); } } else { - LOG(ERROR) << "HTTP: Optaining function \"" << socketContextUpgradeFactoryFunctionName + snode::semantic::appLog().error() << "HTTP: Optaining function \"" << socketContextUpgradeFactoryFunctionName << "\" in plugin failed: " << core::DynamicLoader::dlError(); core::DynamicLoader::dlClose(handle); } @@ -126,17 +127,17 @@ namespace web::http { if (socketContextUpgradePlugins.contains(socketContextUpgradeName)) { socketContextUpgradeFactory = socketContextUpgradePlugins[socketContextUpgradeName].socketContextUpgradeFactory; - LOG(DEBUG) << "HTTP upgrade: plugin '" << socketContextUpgradeName << "' selected from dynamic cache"; + snode::semantic::appLog().debug() << "HTTP upgrade: plugin '" << socketContextUpgradeName << "' selected from dynamic cache"; } else if (linkedSocketContextUpgradePlugins.contains(socketContextUpgradeName)) { socketContextUpgradeFactory = linkedSocketContextUpgradePlugins[socketContextUpgradeName](); - LOG(DEBUG) << "HTTP upgrade: plugin '" << socketContextUpgradeName << "' selected from static cache"; + snode::semantic::appLog().debug() << "HTTP upgrade: plugin '" << socketContextUpgradeName << "' selected from static cache"; } else if (!onlyLinked) { socketContextUpgradeFactory = load(socketContextUpgradeName); - LOG(DEBUG) << "HTTP upgrade: plugin '" << socketContextUpgradeName << "' loaded and added to dynamic cache"; + snode::semantic::appLog().debug() << "HTTP upgrade: plugin '" << socketContextUpgradeName << "' loaded and added to dynamic cache"; } else { - LOG(WARNING) << "HTTP upgrade: plugin '" << socketContextUpgradeName << "' not found"; + snode::semantic::appLog().warn() << "HTTP upgrade: plugin '" << socketContextUpgradeName << "' not found"; } return socketContextUpgradeFactory; diff --git a/src/web/http/client/Request.cpp b/src/web/http/client/Request.cpp index 7e6faf8545..cd4dd87e6d 100644 --- a/src/web/http/client/Request.cpp +++ b/src/web/http/client/Request.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -364,7 +365,7 @@ namespace web::http::client { [masterRequest = this->masterRequest, connectionName = this->connectionName, onResponseReceived]( const std::shared_ptr& request, const std::shared_ptr& response) { if (!masterRequest.expired() && masterRequest.lock()->isConnected()) { - LOG(DEBUG) << connectionName << " HTTP upgrade: Response to upgrade request: " << request->method << " " + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: Response to upgrade request: " << request->method << " " << request->url << " " << "HTTP/" << request->httpMajor << "." << request->httpMinor << "\n" << httputils::toString(response->httpVersion, @@ -383,40 +384,40 @@ namespace web::http::client { if (socketContextUpgradeFactory != nullptr) { socketContextUpgradeName = socketContextUpgradeFactory->name(); - LOG(DEBUG) << connectionName + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: SocketContextUpgradeFactory create success for: " << socketContextUpgradeName; core::socket::stream::SocketContext* socketContextUpgrade = socketContextUpgradeFactory->create(masterRequest.lock()->getSocketContext()->getSocketConnection()); if (socketContextUpgrade != nullptr) { - LOG(DEBUG) << connectionName + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: SocketContextUpgrade create success for: " << socketContextUpgradeName; masterRequest.lock()->getSocketContext()->getSocketConnection()->setSocketContext(socketContextUpgrade); } else { - LOG(DEBUG) << connectionName + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: SocketContextUpgrade create failed for: " << socketContextUpgradeName; masterRequest.lock()->getSocketContext()->close(); } } else { - LOG(DEBUG) << connectionName << " HTTP upgrade: SocketContextUpgradeFactory not supported by server: " + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: SocketContextUpgradeFactory not supported by server: " << request->header("upgrade"); masterRequest.lock()->getSocketContext()->close(); } } else { - LOG(DEBUG) << connectionName << " HTTP upgrade: No upgrade requested"; + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: No upgrade requested"; masterRequest.lock()->getSocketContext()->close(); } - LOG(DEBUG) << connectionName << " HTTP upgrade: bootstrap " + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: bootstrap " << (!socketContextUpgradeName.empty() ? "success" : "failed"); - LOG(DEBUG) << " Protocol selected: " << socketContextUpgradeName; - LOG(DEBUG) << " requested: " << request->header("upgrade"); - LOG(DEBUG) << " Subprotocol selected: " << response->get("Sec-WebSocket-Protocol"); - LOG(DEBUG) << " requested: " << request->header("Sec-WebSocket-Protocol"); + snode::semantic::appLog().debug() << " Protocol selected: " << socketContextUpgradeName; + snode::semantic::appLog().debug() << " requested: " << request->header("upgrade"); + snode::semantic::appLog().debug() << " Subprotocol selected: " << response->get("Sec-WebSocket-Protocol"); + snode::semantic::appLog().debug() << " requested: " << request->header("Sec-WebSocket-Protocol"); onResponseReceived(request, response, !socketContextUpgradeName.empty()); } @@ -467,7 +468,7 @@ namespace web::http::client { [masterRequest = this->masterRequest, connectionName = this->connectionName, onError]( [[maybe_unused]] const std::shared_ptr& request, const std::string& status) { if (!masterRequest.expired() && masterRequest.lock()->isConnected()) { - LOG(DEBUG) << connectionName << " error in response: " << status; + snode::semantic::appLog().debug() << connectionName << " error in response: " << status; masterRequest.lock()->getSocketContext()->close(); onError(); } @@ -618,19 +619,19 @@ namespace web::http::client { web::http::client::SocketContextUpgradeFactorySelector::instance()->select(protocols, *this); if (socketContextUpgradeFactory != nullptr) { - LOG(DEBUG) << connectionName << " HTTP: " + snode::semantic::appLog().debug() << connectionName << " HTTP: " << "SocketContextUpgradeFactory create success: " << socketContextUpgradeFactory->name(); - LOG(DEBUG) << connectionName << " HTTP: Initiating upgrade: " << method << " " << url + snode::semantic::appLog().debug() << connectionName << " HTTP: Initiating upgrade: " << method << " " << url << " HTTP/" + std::to_string(httpMajor) + "." + std::to_string(httpMinor); } else { - LOG(DEBUG) << connectionName << " HTTP: " + snode::semantic::appLog().debug() << connectionName << " HTTP: " << "SocketContextUpgradeFactory create failed: " << protocols; - LOG(DEBUG) << connectionName << " HTTP: Not initiating upgrade " << method << " " << url + snode::semantic::appLog().debug() << connectionName << " HTTP: Not initiating upgrade " << method << " " << url << " HTTP/" + std::to_string(httpMajor) + "." + std::to_string(httpMinor); } - LOG(DEBUG) << connectionName << " HTTP: Upgrade request:\n" + snode::semantic::appLog().debug() << connectionName << " HTTP: Upgrade request:\n" << httputils::toString(method, url, "HTTP/" + std::to_string(httpMajor) + "." + std::to_string(httpMinor), diff --git a/src/web/http/client/SocketContext.cpp b/src/web/http/client/SocketContext.cpp index 93b3d62d4c..e64609a2c2 100644 --- a/src/web/http/client/SocketContext.cpp +++ b/src/web/http/client/SocketContext.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -87,16 +88,16 @@ namespace web::http::client { SocketContext::~SocketContext() { if (!deliveredRequests.empty()) { - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " HTTP: Responses missed"; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " HTTP: Responses missed"; for (const std::shared_ptr& request : deliveredRequests) { - LOG(DEBUG) << " " << request->method << " " << request->url << " HTTP/" << request->httpMajor << "." << request->httpMinor; + snode::semantic::appLog().debug() << " " << request->method << " " << request->url << " HTTP/" << request->httpMajor << "." << request->httpMinor; } } if (!pendingRequests.empty()) { - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " HTTP: Requests ignored"; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " HTTP: Requests ignored"; for (const std::shared_ptr& request : pendingRequests) { - LOG(DEBUG) << " " << request->method << " " << request->url << " HTTP/" << request->httpMajor << "." << request->httpMinor; + snode::semantic::appLog().debug() << " " << request->method << " " << request->url << " HTTP/" << request->httpMajor << "." << request->httpMinor; } } } @@ -112,7 +113,7 @@ namespace web::http::client { if ((flags == Flags::NONE || (flags & Flags::HTTP11) == Flags::HTTP11 || (flags & Flags::KEEPALIVE) == Flags::KEEPALIVE) && (flags & Flags::CLOSE) != Flags::CLOSE) { - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") accepted: " << requestLine; flags = (flags & Flags::HTTP11) | ((request->httpMajor == 1 && request->httpMinor == 1) ? Flags::HTTP11 : Flags::NONE); flags = (flags & Flags::HTTP10) | ((request->httpMajor == 1 && request->httpMinor == 0) ? Flags::HTTP10 : Flags::NONE); @@ -122,7 +123,7 @@ namespace web::http::client { pendingRequests.push_back(request); - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") queued: " << requestLine + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") queued: " << requestLine << " - QueueSize = " << pendingRequests.size() << " - Flags: " << flags << " - " << web::http::ciContains(request->header("Connection"), "close"); @@ -130,10 +131,10 @@ namespace web::http::client { initiateRequest(); } } else { - LOG(WARNING) << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count + snode::semantic::appLog().warn() << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") rejected: " << requestLine; - LOG(WARNING) << httputils::toString(request->method, + snode::semantic::appLog().warn() << httputils::toString(request->method, request->url, "HTTP/" + std::to_string(request->httpMajor) + "." + std::to_string(request->httpMinor), request->getQueries(), @@ -156,10 +157,10 @@ namespace web::http::client { .append(".") .append(std::to_string(request->httpMinor)); - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") start: " << requestLine; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") start: " << requestLine; if (!request->initiate(request)) { - LOG(WARNING) << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count + snode::semantic::appLog().warn() << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") delivering failed: " << requestLine; core::EventReceiver::atNextTick([masterRequest = std::weak_ptr(masterRequest)]() { @@ -171,7 +172,7 @@ namespace web::http::client { if (!socketContext->pendingRequests.empty()) { const std::shared_ptr& request = socketContext->pendingRequests.front(); - LOG(DEBUG) << socketContext->getSocketConnection()->getConnectionName() << " HTTP: Request (" + snode::semantic::appLog().debug() << socketContext->getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") dequeued: " << request->method << " " << request->url << " HTTP/" << request->httpMajor << "." << request->httpMinor; @@ -197,7 +198,7 @@ namespace web::http::client { .append(std::to_string(currentRequest->httpMinor)); if (success) { - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " HTTP: Request (" << currentRequest->count + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " HTTP: Request (" << currentRequest->count << ") delivered: " << requestLine << " " << pendingRequests.size(); deliveredRequests.push_back(currentRequest); @@ -210,7 +211,7 @@ namespace web::http::client { if (socketContext != nullptr) { const std::shared_ptr& request = socketContext->pendingRequests.front(); - LOG(DEBUG) << socketContext->getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count + snode::semantic::appLog().debug() << socketContext->getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") dequeued: " << request->method << " " << request->url << " HTTP/" << request->httpMajor << "." << request->httpMinor; @@ -220,7 +221,7 @@ namespace web::http::client { }); } } else { - LOG(WARNING) << getSocketConnection()->getConnectionName() << " HTTP: Request (" << currentRequest->count + snode::semantic::appLog().warn() << getSocketConnection()->getConnectionName() << " HTTP: Request (" << currentRequest->count << ") deliver failed: " << requestLine; shutdownWrite(); @@ -229,7 +230,7 @@ namespace web::http::client { void SocketContext::responseStarted() { if (deliveredRequests.empty()) { - LOG(ERROR) << getSocketConnection()->getConnectionName() << " HTTP: Response without delivered request"; + snode::semantic::appLog().error() << getSocketConnection()->getConnectionName() << " HTTP: Response without delivered request"; close(); } @@ -247,15 +248,15 @@ namespace web::http::client { .append(".") .append(std::to_string(request->httpMinor)); - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Response received for request (" << request->count + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Response received for request (" << request->count << "): " << requestLine; - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP/" << response->httpMajor << "." << response->httpMinor << " " + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP/" << response->httpMajor << "." << response->httpMinor << " " << response->statusCode << " " << response->reason; request->deliverResponse(request, response); - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") completed: " << requestLine; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Request (" << request->count << ") completed: " << requestLine; requestCompleted(response); } @@ -272,7 +273,7 @@ namespace web::http::client { .append(".") .append(std::to_string(request->httpMinor)); - LOG(WARNING) << getSocketConnection()->getConnectionName() << " HTTP: Response parse error: " << reason << " (" << status + snode::semantic::appLog().warn() << getSocketConnection()->getConnectionName() << " HTTP: Response parse error: " << reason << " (" << status << ") for request (" << request->count << "): " << requestLine << std::string(request->method) .append(" ") @@ -293,11 +294,11 @@ namespace web::http::client { ((response->httpMajor == 0 && response->httpMinor == 0) || (response->httpMajor == 1 && response->httpMinor == 0))); if (httpClose) { - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " HTTP: Connection = Close"; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " HTTP: Connection = Close"; shutdownWrite(); } else { - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " HTTP: Connection = Keep-Alive"; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " HTTP: Connection = Keep-Alive"; if (!pipelinedRequests && !pendingRequests.empty()) { core::EventReceiver::atNextTick([masterRequest = std::weak_ptr(masterRequest)]() { @@ -307,7 +308,7 @@ namespace web::http::client { if (socketContext != nullptr) { const std::shared_ptr& request = socketContext->pendingRequests.front(); - LOG(DEBUG) << socketContext->getSocketConnection()->getConnectionName() << " HTTP: Initiating request (" + snode::semantic::appLog().debug() << socketContext->getSocketConnection()->getConnectionName() << " HTTP: Initiating request (" << request->count << "): " << request->method << " " << request->url << " HTTP/" << request->httpMajor << "." << request->httpMinor; @@ -326,7 +327,7 @@ namespace web::http::client { } void SocketContext::onConnected() { - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Connected"; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Connected"; onHttpConnected(masterRequest); } @@ -360,11 +361,11 @@ namespace web::http::client { masterRequest->disconnect(); onHttpDisconnected(masterRequest); - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Received disconnect"; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Received disconnect"; } bool SocketContext::onSignal([[maybe_unused]] int signum) { - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Received signal " << signum; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Received signal " << signum; return true; } diff --git a/src/web/http/client/SocketContextUpgradeFactorySelector.cpp b/src/web/http/client/SocketContextUpgradeFactorySelector.cpp index a09a7c8ac9..11b87548b7 100644 --- a/src/web/http/client/SocketContextUpgradeFactorySelector.cpp +++ b/src/web/http/client/SocketContextUpgradeFactorySelector.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -66,7 +67,7 @@ namespace web::http::client { #if !defined(NDEBUG) if (const char* httpUpgradeInstallLibdirEnv = std::getenv("HTTP_UPGRADE_INSTALL_LIBDIR")) { - LOG(WARNING) << "HTTP upgrade: Overriding http upgrade library dir"; + snode::semantic::appLog().warn() << "HTTP upgrade: Overriding http upgrade library dir"; httpUpgradeInstallLibdir = std::string(httpUpgradeInstallLibdirEnv); } #endif diff --git a/src/web/http/client/tools/EventSource.h b/src/web/http/client/tools/EventSource.h index 2cc19e32a3..8d851e0827 100644 --- a/src/web/http/client/tools/EventSource.h +++ b/src/web/http/client/tools/EventSource.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -288,24 +289,24 @@ namespace web::http::client::tools { sharedState->path = path; sharedState->origin = scheme + "://" + socketAddress.toString(false); - LOG(TRACE) << "Origin: " << sharedState->origin; - LOG(TRACE) << " Path: " << sharedState->path; + snode::semantic::appLog().trace() << "Origin: " << sharedState->origin; + snode::semantic::appLog().trace() << " Path: " << sharedState->path; const std::weak_ptr eventSourceWeak = this->weak_from_this(); client = std::make_shared( [eventSourceWeak](SocketConnection* socketConnection) { - LOG(DEBUG) << socketConnection->getConnectionName() << ": OnConnect"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnConnect"; if (const std::shared_ptr eventStream = eventSourceWeak.lock()) { eventStream->socketConnection = socketConnection; } }, [](SocketConnection* socketConnection) { - LOG(DEBUG) << socketConnection->getConnectionName() << ": OnConnected"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnConnected"; }, [eventSourceWeak, sharedState = this->sharedState, sharedConfig = this->sharedConfig](SocketConnection* socketConnection) { - LOG(DEBUG) << socketConnection->getConnectionName() << " : OnDisconnect"; + snode::semantic::appLog().debug() << socketConnection->getConnectionName() << " : OnDisconnect"; if (const std::shared_ptr eventSource = eventSourceWeak.lock()) { eventSource->socketConnection = nullptr; @@ -338,7 +339,7 @@ namespace web::http::client::tools { const std::shared_ptr& masterRequest) { const std::string connectionName = masterRequest->getSocketContext()->getSocketConnection()->getConnectionName(); - LOG(DEBUG) << connectionName << ": OnRequestStart"; + snode::semantic::appLog().debug() << connectionName << ": OnRequestStart"; if (!sharedState->lastId.empty()) { masterRequest->set("Last-Event-ID", sharedState->lastId); @@ -360,13 +361,13 @@ namespace web::http::client::tools { masterRequest->getSocketContext()->close(); } } else { - LOG(DEBUG) << connectionName << ": server-sent event: server disconnect"; + snode::semantic::appLog().debug() << connectionName << ": server-sent event: server disconnect"; } return consumed; }, [sharedState, sharedConfig, connectionName]() { - LOG(DEBUG) << connectionName << ": server-sent event stream start"; + snode::semantic::appLog().debug() << connectionName << ": server-sent event stream start"; sharedState->ready = ReadyState::OPEN; @@ -386,7 +387,7 @@ namespace web::http::client::tools { } }, [sharedState, connectionName]() { - LOG(DEBUG) << connectionName + snode::semantic::appLog().debug() << connectionName << ": not an server-sent event endpoint: " << sharedState->origin + sharedState->path; if (auto it = sharedState->onEventListener.find("error"); it != sharedState->onEventListener.end()) { EventSource::MessageEvent e{"error", "", sharedState->lastId, sharedState->origin}; @@ -406,7 +407,7 @@ namespace web::http::client::tools { } }, [](const std::shared_ptr& req) { - LOG(DEBUG) << req->getConnectionName() << ": OnRequestEnd"; + snode::semantic::appLog().debug() << req->getConnectionName() << ": OnRequestEnd"; }); client->getConfig()->Remote::setSocketAddress(socketAddress); @@ -422,16 +423,16 @@ namespace web::http::client::tools { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - LOG(DEBUG) << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::semantic::appLog().debug() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - LOG(DEBUG) << instanceName << ": disabled"; + snode::semantic::appLog().debug() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - LOG(DEBUG) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().debug() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - LOG(DEBUG) << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::semantic::appLog().debug() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/web/http/legacy/in/EventSource.h b/src/web/http/legacy/in/EventSource.h index ab0c6b23a0..45f08f43f1 100644 --- a/src/web/http/legacy/in/EventSource.h +++ b/src/web/http/legacy/in/EventSource.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -107,10 +108,10 @@ namespace web::http::legacy::in { if (scheme == "http") { eventSource = EventSource(scheme, net::in::SocketAddress(host, port), path + query); } else { - LOG(ERROR) << "Scheme not valid: " << scheme; + snode::semantic::appLog().error() << "Scheme not valid: " << scheme; } } else { - LOG(ERROR) << "EventSource url not accepted: " << url; + snode::semantic::appLog().error() << "EventSource url not accepted: " << url; } return eventSource; diff --git a/src/web/http/legacy/in6/EventSource.h b/src/web/http/legacy/in6/EventSource.h index 417bfc5938..5897491a0f 100644 --- a/src/web/http/legacy/in6/EventSource.h +++ b/src/web/http/legacy/in6/EventSource.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -105,10 +106,10 @@ namespace web::http::legacy::in6 { if (scheme == "http") { eventSource = EventSource(scheme, net::in6::SocketAddress(host, port), path + query); } else { - LOG(ERROR) << "Scheme not valid: " << scheme; + snode::semantic::appLog().error() << "Scheme not valid: " << scheme; } } else { - LOG(ERROR) << "EventSource url not accepted: " << url; + snode::semantic::appLog().error() << "EventSource url not accepted: " << url; } return eventSource; diff --git a/src/web/http/legacy/rc/EventSource.h b/src/web/http/legacy/rc/EventSource.h index 4183c4cec0..bf590994d4 100644 --- a/src/web/http/legacy/rc/EventSource.h +++ b/src/web/http/legacy/rc/EventSource.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -106,7 +107,7 @@ namespace web::http::legacy::rc { eventSource = EventSource(scheme, net::rc::SocketAddress(addr, chan), path + query); } else { - LOG(ERROR) << "EventSource RFCOMM url not accepted: " << url; + snode::semantic::appLog().error() << "EventSource RFCOMM url not accepted: " << url; } return eventSource; diff --git a/src/web/http/legacy/un/EventSource.h b/src/web/http/legacy/un/EventSource.h index 85da23c486..90b18d92f9 100644 --- a/src/web/http/legacy/un/EventSource.h +++ b/src/web/http/legacy/un/EventSource.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -132,10 +133,10 @@ namespace web::http::legacy::un { eventSource = EventSource(scheme, net::un::SocketAddress(socketPath), httpPath + query); } else { - LOG(ERROR) << "UNIX socket must decode to absolute ('/..') or abstract ('@name'): " << sockToken; + snode::semantic::appLog().error() << "UNIX socket must decode to absolute ('/..') or abstract ('@name'): " << sockToken; } } else { - LOG(ERROR) << "EventSource unix-domain url not accepted: " << url; + snode::semantic::appLog().error() << "EventSource unix-domain url not accepted: " << url; } return eventSource; diff --git a/src/web/http/server/Response.cpp b/src/web/http/server/Response.cpp index 4b9673e6e4..2bb9ad074f 100644 --- a/src/web/http/server/Response.cpp +++ b/src/web/http/server/Response.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -252,7 +253,7 @@ namespace web::http::server { std::string socketContextUpgradeName; if (request != nullptr) { - LOG(DEBUG) << connectionName << " HTTP: Initiating upgrade: " << request->method << " " << request->url + snode::semantic::appLog().debug() << connectionName << " HTTP: Initiating upgrade: " << request->method << " " << request->url << " HTTP/" + std::to_string(httpMajor) + "." + std::to_string(httpMinor) << "\n" << httputils::toString(request->method, request->url, @@ -269,17 +270,17 @@ namespace web::http::server { if (socketContextUpgradeFactory != nullptr) { socketContextUpgradeName = socketContextUpgradeFactory->name(); - LOG(DEBUG) << connectionName + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: SocketContextUpgradeFactory create success for: " << socketContextUpgradeName; core::socket::stream::SocketContext* socketContextUpgrade = socketContextUpgradeFactory->create(socketContext->getSocketConnection()); if (socketContextUpgrade != nullptr) { - LOG(DEBUG) << connectionName + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: SocketContextUpgrade create success for: " << socketContextUpgradeName; - LOG(DEBUG) << connectionName << " HTTP upgrade: Response to upgrade request: " << request->method << " " + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: Response to upgrade request: " << request->method << " " << request->url << " " << "HTTP/" << request->httpMajor << "." << request->httpMinor << "\n" << httputils::toString("HTTP/" + std::to_string(httpMajor) + "." + std::to_string(httpMinor), std::to_string(statusCode), @@ -290,37 +291,37 @@ namespace web::http::server { socketContext->getSocketConnection()->setSocketContext(socketContextUpgrade); } else { - LOG(DEBUG) << connectionName + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: SocketContextUpgrade create failed for: " << socketContextUpgradeName; set("Connection", "close").status(404); } } else { - LOG(DEBUG) << connectionName + snode::semantic::appLog().debug() << connectionName << " SocketContextUpgradeFactory create failed for all of: " << request->get("upgrade"); set("Connection", "close").status(404); } } else { - LOG(DEBUG) << connectionName << " HTTP upgrade: No upgrade requested"; + snode::semantic::appLog().debug() << connectionName << " HTTP upgrade: No upgrade requested"; set("Connection", "close").status(400); } } else { - LOG(ERROR) << connectionName << " HTTP upgrade: Request has gone away"; + snode::semantic::appLog().error() << connectionName << " HTTP upgrade: Request has gone away"; set("Connection", "close").status(500); } - LOG(DEBUG) << connectionName << " HTTP: Upgrade bootstrap " << (!socketContextUpgradeName.empty() ? "success" : "failed"); - LOG(DEBUG) << " Protocol selected: " << socketContextUpgradeName; - LOG(DEBUG) << " requested: " << request->get("upgrade"); - LOG(DEBUG) << " Subprotocol selected: " << header("Sec-WebSocket-Protocol"); - LOG(DEBUG) << " requested: " << request->get("Sec-WebSocket-Protocol"); + snode::semantic::appLog().debug() << connectionName << " HTTP: Upgrade bootstrap " << (!socketContextUpgradeName.empty() ? "success" : "failed"); + snode::semantic::appLog().debug() << " Protocol selected: " << socketContextUpgradeName; + snode::semantic::appLog().debug() << " requested: " << request->get("upgrade"); + snode::semantic::appLog().debug() << " Subprotocol selected: " << header("Sec-WebSocket-Protocol"); + snode::semantic::appLog().debug() << " requested: " << request->get("Sec-WebSocket-Protocol"); status(socketContextUpgradeName); } else { - LOG(ERROR) << "HTTP upgrade: Unexpected disconnect"; + snode::semantic::appLog().error() << "HTTP upgrade: Unexpected disconnect"; } } diff --git a/src/web/http/server/SocketContext.cpp b/src/web/http/server/SocketContext.cpp index a16102f038..fd1248d4d4 100644 --- a/src/web/http/server/SocketContext.cpp +++ b/src/web/http/server/SocketContext.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -67,10 +68,10 @@ namespace web::http::server { , parser( this, [this]() { - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Request start"; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Request start"; }, [this](web::http::server::Request&& request) { - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Request parse success: " << request.method << " " + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Request parse success: " << request.method << " " << request.url << " HTTP/" << request.httpMajor << "." << request.httpMinor; pendingRequests.emplace_back(std::make_shared(std::move(request))); @@ -80,7 +81,7 @@ namespace web::http::server { } }, [this](int status, const std::string& reason) { - LOG(ERROR) << getSocketConnection()->getConnectionName() << " HTTP: Request parse error: " << reason << " (" << status + snode::semantic::appLog().error() << getSocketConnection()->getConnectionName() << " HTTP: Request parse error: " << reason << " (" << status << ") "; shutdownRead(); @@ -109,7 +110,7 @@ namespace web::http::server { const std::shared_ptr& pendingRequest = pendingRequests.front(); if (pendingRequest->status == 0) { - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Request deliver: " << pendingRequest->method << " " + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Request deliver: " << pendingRequest->method << " " << pendingRequest->url << " HTTP/" << pendingRequest->httpMajor << "." << pendingRequest->httpMinor; masterResponse->init(); @@ -134,7 +135,7 @@ namespace web::http::server { masterResponse->status(pendingRequest->status).send(pendingRequest->reason); } } else { - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: No more pending request"; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: No more pending request"; } } @@ -148,9 +149,9 @@ namespace web::http::server { getSocketConnection()->setReadTimeout(0); } - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Response start for request: " << pendingRequest->method + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Response start for request: " << pendingRequest->method << " " << pendingRequest->url << " HTTP/" << pendingRequest->httpMajor << "." << pendingRequest->httpMinor; - LOG(INFO) << getSocketConnection()->getConnectionName() << " " + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " " << "HTTP/" + std::to_string(response.httpMajor) .append(".") .append(std::to_string(response.httpMinor)) @@ -165,7 +166,7 @@ namespace web::http::server { if (success) { requestCompleted(response); } else { - LOG(WARNING) << getSocketConnection()->getConnectionName() << " HTTP: Response completed with error: " << response.statusCode + snode::semantic::appLog().warn() << getSocketConnection()->getConnectionName() << " HTTP: Response completed with error: " << response.statusCode << " " << StatusCode::reason(response.statusCode); close(); @@ -176,9 +177,9 @@ namespace web::http::server { const std::shared_ptr request = std::move(pendingRequests.front()); pendingRequests.pop_front(); - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Response completed for request: " << request->method << " " + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Response completed for request: " << request->method << " " << request->url << " HTTP/" << request->httpMajor << "." << request->httpMinor; - LOG(INFO) << getSocketConnection()->getConnectionName() << " " + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " " << "HTTP/" + std::to_string(response.httpMajor) .append(".") .append(std::to_string(response.httpMinor)) @@ -192,11 +193,11 @@ namespace web::http::server { ((response.httpMajor == 0 && response.httpMinor == 9) || (response.httpMajor == 1 && response.httpMinor == 0))); if (httpClose) { - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " HTTP: Connection = Close"; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " HTTP: Connection = Close"; shutdownWrite(); } else { - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " HTTP: Connection = Keep-Alive"; + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " HTTP: Connection = Keep-Alive"; if (!pendingRequests.empty()) { core::EventReceiver::atNextTick([response = std::weak_ptr(masterResponse)]() { @@ -213,7 +214,7 @@ namespace web::http::server { } void SocketContext::onConnected() { - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Connected"; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Connected"; for (const auto& onConnectEventReceiver : onConnectEventReceiverList) { onConnectEventReceiver(); @@ -233,7 +234,7 @@ namespace web::http::server { void SocketContext::onDisconnected() { masterResponse->disconnect(); - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Received disconnect"; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Received disconnect"; for (const auto& onDisconnectEventReceiver : onDisconnectEventReceiverList) { onDisconnectEventReceiver(); @@ -241,7 +242,7 @@ namespace web::http::server { } bool SocketContext::onSignal(int signum) { - LOG(INFO) << getSocketConnection()->getConnectionName() << " HTTP: Received signal " << signum; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " HTTP: Received signal " << signum; return true; } diff --git a/src/web/http/server/SocketContextUpgradeFactorySelector.cpp b/src/web/http/server/SocketContextUpgradeFactorySelector.cpp index 36e7d9884b..99fd00c08f 100644 --- a/src/web/http/server/SocketContextUpgradeFactorySelector.cpp +++ b/src/web/http/server/SocketContextUpgradeFactorySelector.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -66,7 +67,7 @@ namespace web::http::server { #if !defined(NDEBUG) if (const char* httpUpgradeInstallLibdirEnv = std::getenv("HTTP_UPGRADE_INSTALL_LIBDIR")) { - LOG(WARNING) << "HTTP upgrade: Overriding http upgrade library dir"; + snode::semantic::appLog().warn() << "HTTP upgrade: Overriding http upgrade library dir"; httpUpgradeInstallLibdir = std::string(httpUpgradeInstallLibdirEnv); } #endif diff --git a/src/web/http/tls/in/EventSource.h b/src/web/http/tls/in/EventSource.h index 9d294c3a8b..6f5a3487e2 100644 --- a/src/web/http/tls/in/EventSource.h +++ b/src/web/http/tls/in/EventSource.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -105,10 +106,10 @@ namespace web::http::tls::in { if (scheme == "https") { eventSource = EventSource(scheme, net::in::SocketAddress(host, port), path + query); } else { - LOG(ERROR) << "Scheme not valid: " << scheme; + snode::semantic::appLog().error() << "Scheme not valid: " << scheme; } } else { - LOG(ERROR) << "EventSource url not accepted: " << url; + snode::semantic::appLog().error() << "EventSource url not accepted: " << url; } return eventSource; diff --git a/src/web/http/tls/in6/EventSource.h b/src/web/http/tls/in6/EventSource.h index 6976c14511..f13b3efc8f 100644 --- a/src/web/http/tls/in6/EventSource.h +++ b/src/web/http/tls/in6/EventSource.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -105,10 +106,10 @@ namespace web::http::tls::in6 { if (scheme == "https") { eventSource = EventSource(scheme, net::in6::SocketAddress(host, port), path + query); } else { - LOG(ERROR) << "Scheme not valid: " << scheme; + snode::semantic::appLog().error() << "Scheme not valid: " << scheme; } } else { - LOG(ERROR) << "EventSource url not accepted: " << url; + snode::semantic::appLog().error() << "EventSource url not accepted: " << url; } return eventSource; diff --git a/src/web/http/tls/rc/EventSource.h b/src/web/http/tls/rc/EventSource.h index a94f63b6fa..f77ad40156 100644 --- a/src/web/http/tls/rc/EventSource.h +++ b/src/web/http/tls/rc/EventSource.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -106,7 +107,7 @@ namespace web::http::tls::rc { eventSource = EventSource(scheme, net::rc::SocketAddress(addr, chan), path + query); } else { - LOG(ERROR) << "EventSource RFCOMM url not accepted: " << url; + snode::semantic::appLog().error() << "EventSource RFCOMM url not accepted: " << url; } return eventSource; diff --git a/src/web/http/tls/un/EventSource.h b/src/web/http/tls/un/EventSource.h index 503f18bc65..d2cba19f4f 100644 --- a/src/web/http/tls/un/EventSource.h +++ b/src/web/http/tls/un/EventSource.h @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -132,10 +133,10 @@ namespace web::http::tls::un { eventSource = EventSource(scheme, net::un::SocketAddress(socketPath), httpPath + query); } else { - LOG(ERROR) << "UNIX socket must decode to absolute ('/..') or abstract ('@name'): " << sockToken; + snode::semantic::appLog().error() << "UNIX socket must decode to absolute ('/..') or abstract ('@name'): " << sockToken; } } else { - LOG(ERROR) << "EventSource unix-domain url not accepted: " << url; + snode::semantic::appLog().error() << "EventSource unix-domain url not accepted: " << url; } return eventSource; diff --git a/src/web/websocket/Receiver.cpp b/src/web/websocket/Receiver.cpp index f9e65b60b7..62068b4123 100644 --- a/src/web/websocket/Receiver.cpp +++ b/src/web/websocket/Receiver.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -127,7 +128,7 @@ namespace web::websocket { } else { parserState = ParserState::ERROR; errorState = 1002; - LOG(ERROR) << "WebSocket: Error opcode in continuation frame"; + snode::semantic::appLog().error() << "WebSocket: Error opcode in continuation frame"; } continuation = !fin; } @@ -281,7 +282,7 @@ namespace web::websocket { } } - LOG(TRACE) << "WebSocket receive: Frame data\n" << utils::hexDump(payloadChunk, payloadChunkLen, 32, true); + snode::semantic::appLog().trace() << "WebSocket receive: Frame data\n" << utils::hexDump(payloadChunk, payloadChunkLen, 32, true); onMessageData(payloadChunk, payloadChunkLen); diff --git a/src/web/websocket/SocketContextUpgrade.hpp b/src/web/websocket/SocketContextUpgrade.hpp index 463cb8e662..7722ed9031 100644 --- a/src/web/websocket/SocketContextUpgrade.hpp +++ b/src/web/websocket/SocketContextUpgrade.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -115,7 +116,7 @@ namespace web::websocket { template void SocketContextUpgrade::sendClose(const char* message, std::size_t messageLength) { if (!closeSent) { - LOG(DEBUG) << this->getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name + snode::semantic::appLog().debug() << this->getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name << "' sending close to peer"; sendMessage(8, message, messageLength); @@ -186,12 +187,12 @@ namespace web::websocket { case SubProtocolContext::OpCode::CLOSE: if (closeSent) { // active close closeSent = false; - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name << "' close confirmed from peer"; shutdownWrite(); } else { // passive close - LOG(DEBUG) << getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name + snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name << "' close request received - replying with close"; sendClose(pongCloseData.data(), pongCloseData.length()); @@ -219,14 +220,14 @@ namespace web::websocket { template void SocketContextUpgrade::onConnected() { - LOG(INFO) << getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name << "' connect"; + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name << "' connect"; subProtocol->attach(); } template void SocketContextUpgrade::onDisconnected() { subProtocol->detach(); - LOG(INFO) << getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name + snode::semantic::appLog().info() << getSocketConnection()->getConnectionName() << " WebSocketContext: Subprotocol '" << subProtocol->name << "' disconnected"; } diff --git a/src/web/websocket/SubProtocol.hpp b/src/web/websocket/SubProtocol.hpp index 3238c41cee..ba63e52825 100644 --- a/src/web/websocket/SubProtocol.hpp +++ b/src/web/websocket/SubProtocol.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -69,7 +70,7 @@ namespace web::websocket { sendPing(); flyingPings++; } else { - LOG(WARNING) << this->subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" + snode::semantic::appLog().warn() << this->subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << this->name << "': MaxFlyingPings exceeded - closing"; sendClose(); @@ -129,7 +130,7 @@ namespace web::websocket { template void SubProtocol::sendPing(const char* reason, std::size_t reasonLength) const { - LOG(DEBUG) << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': Ping sent"; + snode::semantic::appLog().debug() << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': Ping sent"; subProtocolContext->sendPing(reason, reasonLength); } @@ -141,7 +142,7 @@ namespace web::websocket { template void SubProtocol::attach() { - LOG(DEBUG) << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': start"; + snode::semantic::appLog().debug() << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': start"; onConnected(); } @@ -150,15 +151,15 @@ namespace web::websocket { void SubProtocol::detach() { onDisconnected(); - LOG(DEBUG) << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': stopped"; + snode::semantic::appLog().debug() << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': stopped"; - LOG(DEBUG) << " Total Payload sent: " << getPayloadTotalSent(); - LOG(DEBUG) << " Total Payload processed: " << getPayloadTotalRead(); + snode::semantic::appLog().debug() << " Total Payload sent: " << getPayloadTotalSent(); + snode::semantic::appLog().debug() << " Total Payload processed: " << getPayloadTotalRead(); } template void SubProtocol::onPongReceived() { - LOG(DEBUG) << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': Pong received"; + snode::semantic::appLog().debug() << subProtocolContext->getSocketConnection()->getConnectionName() << " Subprotocol '" << name << "': Pong received"; flyingPings = 0; } diff --git a/src/web/websocket/SubProtocolFactorySelector.hpp b/src/web/websocket/SubProtocolFactorySelector.hpp index 229d3c5ae4..e678f6a7cb 100644 --- a/src/web/websocket/SubProtocolFactorySelector.hpp +++ b/src/web/websocket/SubProtocolFactorySelector.hpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -67,13 +68,13 @@ namespace web::websocket { subProtocolFactory = getSubProtocolFactory(); if (subProtocolFactory != nullptr) { subProtocolFactory->setHandle(handle); - LOG(DEBUG) << "WebSocket: SubProtocolFactory create success: " << subProtocolName; + snode::semantic::appLog().debug() << "WebSocket: SubProtocolFactory create success: " << subProtocolName; } else { - LOG(DEBUG) << "WebSocket: SubProtocolFactory create failed: " << subProtocolName; + snode::semantic::appLog().debug() << "WebSocket: SubProtocolFactory create failed: " << subProtocolName; core::DynamicLoader::dlClose(handle); } } else { - LOG(DEBUG) << "WebSocket: Optaining function \"" << subProtocolFactoryFunctionName + snode::semantic::appLog().debug() << "WebSocket: Optaining function \"" << subProtocolFactoryFunctionName << "\" in plugin failed: " << core::DynamicLoader::dlError(); core::DynamicLoader::dlClose(handle); } @@ -90,19 +91,19 @@ namespace web::websocket { if (subProtocolFactories.contains(subProtocolName)) { subProtocolFactory = subProtocolFactories[subProtocolName]; - LOG(DEBUG) << "WebSocket subprotocol: plugin '" << subProtocolName << "' selected from dynamic cache"; + snode::semantic::appLog().debug() << "WebSocket subprotocol: plugin '" << subProtocolName << "' selected from dynamic cache"; } else if (linkedSubProtocolFactories.contains(subProtocolName)) { SubProtocolFactory* (*plugin)() = linkedSubProtocolFactories[subProtocolName]; subProtocolFactory = plugin(); - LOG(DEBUG) << "WebSocket subprotocol: plugin '" << subProtocolName << "' selected from static cache"; + snode::semantic::appLog().debug() << "WebSocket subprotocol: plugin '" << subProtocolName << "' selected from static cache"; } else if (!onlyLinked) { subProtocolFactory = load(subProtocolName); subProtocolFactories.insert({subProtocolName, subProtocolFactory}); - LOG(DEBUG) << "WebSocket subprotocol: plugin '" << subProtocolName << "' loaded and added to dynamic cache"; + snode::semantic::appLog().debug() << "WebSocket subprotocol: plugin '" << subProtocolName << "' loaded and added to dynamic cache"; } else { - LOG(WARNING) << "WebSocket subprotocol: plugin '" << subProtocolName << "' not found"; + snode::semantic::appLog().warn() << "WebSocket subprotocol: plugin '" << subProtocolName << "' not found"; } return subProtocolFactory; diff --git a/src/web/websocket/Transmitter.cpp b/src/web/websocket/Transmitter.cpp index 08ea94713e..31edc0bbaf 100644 --- a/src/web/websocket/Transmitter.cpp +++ b/src/web/websocket/Transmitter.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -139,7 +140,7 @@ namespace web::websocket { MaskingKey maskingKeyAsArray = {.keyAsValue = distribution(randomDevice)}; if (payloadLength > 0) { - LOG(TRACE) << "WebSocket send: Frame data\n" << utils::hexDump(payload, payloadLength, 32, true); + snode::semantic::appLog().trace() << "WebSocket send: Frame data\n" << utils::hexDump(payload, payloadLength, 32, true); } if (masking) { diff --git a/src/web/websocket/client/SubProtocolFactorySelector.cpp b/src/web/websocket/client/SubProtocolFactorySelector.cpp index b01292d2d9..db05993c23 100644 --- a/src/web/websocket/client/SubProtocolFactorySelector.cpp +++ b/src/web/websocket/client/SubProtocolFactorySelector.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -80,7 +81,7 @@ namespace web::websocket::client { #if !defined(NDEBUG) if (const char* websocketSubprotocolInstallLibdirEnv = std::getenv("WEBSOCKET_SUBPROTOCOL_INSTALL_LIBDIR")) { - LOG(WARNING) << "WebSocket: Overriding websocket subprotocol library dir"; + snode::semantic::appLog().warn() << "WebSocket: Overriding websocket subprotocol library dir"; websocketSubprotocolInstallLibdir = std::string(websocketSubprotocolInstallLibdirEnv); } #endif diff --git a/src/web/websocket/server/SubProtocolFactorySelector.cpp b/src/web/websocket/server/SubProtocolFactorySelector.cpp index ae43e6e7d4..4d90c26d15 100644 --- a/src/web/websocket/server/SubProtocolFactorySelector.cpp +++ b/src/web/websocket/server/SubProtocolFactorySelector.cpp @@ -1,3 +1,4 @@ +#include /* * SNode.C - A Slim Toolkit for Network Communication * Copyright (C) Volker Christian @@ -80,7 +81,7 @@ namespace web::websocket::server { #if !defined(NDEBUG) if (const char* websocketSubprotocolInstallLibdirEnv = std::getenv("WEBSOCKET_SUBPROTOCOL_INSTALL_LIBDIR")) { - LOG(WARNING) << "WebSocket: Overriding websocket subprotocol library dir"; + snode::semantic::appLog().warn() << "WebSocket: Overriding websocket subprotocol library dir"; websocketSubprotocolInstallLibdir = std::string(websocketSubprotocolInstallLibdirEnv); } #endif