diff --git a/README.md b/README.md index 8ab8ca8980..db945110b3 100644 --- a/README.md +++ b/README.md @@ -2063,7 +2063,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[]) { utils::Config::add_string_option("--web-root", "Root directory of the web site", "[path]"); @@ -2080,11 +2080,11 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const LegacySocketAddress& socketAddress, int errnum) { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); @@ -2102,11 +2102,11 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const TLSSocketAddress& socketAddress, int errnum) { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); @@ -2121,7 +2121,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); @@ -2184,9 +2184,9 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const LegacySocketAddress& socketAddress, int errnum) -> void { if (errnum != 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "LegacyWebApp listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "LegacyWebApp listening on " << socketAddress.toString(); } }); @@ -2205,9 +2205,9 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const TLSSocketAddress& socketAddress, int errnum) -> void { if (errnum != 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "TLSWebApp listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "TLSWebApp listening on " << socketAddress.toString(); } }); diff --git a/src/SemanticLog.h b/src/SemanticLog.h new file mode 100644 index 0000000000..377288a3a7 --- /dev/null +++ b/src/SemanticLog.h @@ -0,0 +1,141 @@ +/* + * snode.c - a slim toolkit for network communication + * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian + * + * SPDX-License-Identifier: LGPL-3.0-or-later + */ + +#ifndef SNODEC_SEMANTICLOG_H +#define SNODEC_SEMANTICLOG_H + +#include + +#include +#include + +namespace logger { + + enum class LogLevel { + Trace, + Debug, + Info, + Warning, + Error, + Critical, + }; + +} // namespace logger + +namespace snode::semantic { + + namespace detail { + + inline el::Level backendLevel(logger::LogLevel level) { + switch (level) { + case logger::LogLevel::Trace: + return el::Level::Trace; + case logger::LogLevel::Debug: + return el::Level::Debug; + case logger::LogLevel::Info: + return el::Level::Info; + case logger::LogLevel::Warning: + return el::Level::Warning; + case logger::LogLevel::Error: + return el::Level::Error; + case logger::LogLevel::Critical: + return el::Level::Fatal; + } + + return el::Level::Info; + } + + inline el::Level captureSystemError(logger::LogLevel level, int errnum) { + errno = errnum; + return backendLevel(level); + } + + } // namespace detail + + class LogStream { + public: + explicit LogStream(logger::LogLevel level) + : writer(detail::backendLevel(level), "", 0, "") { + writer.construct(el::Loggers::getLogger("default")); + } + + template + LogStream& operator<<(const Value& value) { + writer << value; + return *this; + } + + LogStream& operator<<(std::ostream& (*manipulator)(std::ostream&)) { + writer << manipulator; + return *this; + } + + private: + el::base::Writer writer; + }; + + class SystemErrorStream { + public: + SystemErrorStream(logger::LogLevel level, int errnum) + : writer(detail::captureSystemError(level, errnum), "", 0, "") { + writer.construct(el::Loggers::getLogger("default")); + } + + template + SystemErrorStream& operator<<(const Value& value) { + writer << value; + return *this; + } + + SystemErrorStream& operator<<(std::ostream& (*manipulator)(std::ostream&)) { + writer << manipulator; + return *this; + } + + private: + el::base::PErrorWriter writer; + }; + + class AppLog { + public: + LogStream trace() const { + return LogStream(logger::LogLevel::Trace); + } + + LogStream debug() const { + return LogStream(logger::LogLevel::Debug); + } + + LogStream info() const { + return LogStream(logger::LogLevel::Info); + } + + LogStream warn() const { + return LogStream(logger::LogLevel::Warning); + } + + LogStream error() const { + return LogStream(logger::LogLevel::Error); + } + + LogStream critical() const { + return LogStream(logger::LogLevel::Critical); + } + }; + + inline const AppLog& appLog() { + static const AppLog log; + return log; + } + + inline SystemErrorStream sysError(const AppLog&, logger::LogLevel level, int errnum) { + return SystemErrorStream(level, errnum); + } + +} // namespace snode::semantic + +#endif // SNODEC_SEMANTICLOG_H diff --git a/src/apps/configtest.cpp b/src/apps/configtest.cpp index b10dcb8a30..cb8d7160cd 100644 --- a/src/apps/configtest.cpp +++ b/src/apps/configtest.cpp @@ -1,3 +1,4 @@ +#include #include "log/Logger.h" #ifdef __GNUC__ @@ -31,7 +32,7 @@ int main(int argc, char* argv[]) { CLI::Option* filenameOpt = subApp->add_option("-f", filename, "A Filename"); // filenameOpt->default_val("Filenameeeeee"); - VLOG(0) << "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 d2b851800d..4dfd3b685a 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) 2020, 2021, 2022, 2023 Volker Christian @@ -56,59 +57,59 @@ 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); @@ -117,13 +118,13 @@ 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; }); int r1 = 0; @@ -133,36 +134,36 @@ int main(int argc, char* argv[]) { "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(); }); }, @@ -171,146 +172,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 b44eaced64..6f4d24b277 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) 2020, 2021, 2022, 2023 Volker Christian @@ -33,11 +34,11 @@ int main(int argc, char* argv[]) { client.connect([](const SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c connecting to " << socketAddress.toString(); } }); @@ -72,12 +73,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(0) << "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 30807f6390..516a51cf01 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) 2020, 2021, 2022, 2023 Volker Christian @@ -50,11 +51,11 @@ int main(int argc, char* argv[]) { server.listen([](const SocketServer::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); @@ -88,9 +89,9 @@ int main(int argc, char* argv[]) { server.listen("/tmp/testme", 5, [](const SocketServer::Socket& socket, int errnum) -> void { // titan #endif if (errnum != 0) { - PLOG(FATAL) << "listen"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Critical, errno) << "listen"; } else { - VLOG(0) << "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 c7b5412432..8124d7d1c8 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) 2020, 2021, 2022, 2023 Volker Christian @@ -34,7 +35,7 @@ namespace apps::echo::model { } void EchoSocketContext::onConnected() { - VLOG(0) << "Echo connected"; + snode::semantic::appLog().trace() << "Echo connected"; if (role == Role::CLIENT) { sendToPeer("Hello peer! Nice to see you!!!"); @@ -42,7 +43,7 @@ namespace apps::echo::model { } void EchoSocketContext::onDisconnected() { - VLOG(0) << "Echo disconnected"; + snode::semantic::appLog().trace() << "Echo disconnected"; } std::size_t EchoSocketContext::onReceivedFromPeer() { @@ -51,7 +52,7 @@ namespace apps::echo::model { std::size_t junklen = readFromPeer(junk, 4096); if (junklen > 0) { - VLOG(0) << "Data to reflect: " << std::string(junk, junklen); + snode::semantic::appLog().trace() << "Data to reflect: " << std::string(junk, junklen); sendToPeer(junk, junklen); } diff --git a/src/apps/http/httpclient.cpp b/src/apps/http/httpclient.cpp index 48b66cab7c..0da4e8889b 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) 2020, 2021, 2022, 2023 Volker Christian @@ -34,11 +35,11 @@ int main(int argc, char* argv[]) { client.connect([&client](const SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << client.getConfig().getInstanceName() << " connected to " << socketAddress.toString(); + snode::semantic::appLog().trace() << client.getConfig().getInstanceName() << " connected to " << socketAddress.toString(); } }); @@ -72,9 +73,9 @@ int main(int argc, char* argv[]) { client.connect("/tmp/testme", [](const SocketAddress& socketAddress, int errnum) -> void { #endif if (errnum != 0) { - PLOG(ERROR) << "OnError: " << errnum; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << errnum; } else { - VLOG(0) << "snode.c connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c connecting to " << socketAddress.toString(); } #ifdef NET_TYPE diff --git a/src/apps/http/httpclientclientcert.cpp b/src/apps/http/httpclientclientcert.cpp index 346c5d484f..d9af7101c5 100644 --- a/src/apps/http/httpclientclientcert.cpp +++ b/src/apps/http/httpclientclientcert.cpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -34,11 +35,11 @@ int main(int argc, char* argv[]) { client.connect([](const SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c connectedto " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c connectedto " << socketAddress.toString(); } }); @@ -72,9 +73,9 @@ int main(int argc, char* argv[]) { client.connect("/tmp/testme", [](int errnum) -> void { #endif if (errnum != 0) { - PLOG(ERROR) << "OnError: " << errnum; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << errnum; } else { - VLOG(0) << "snode.c connected"; + snode::semantic::appLog().trace() << "snode.c connected"; } #ifdef NET_TYPE diff --git a/src/apps/http/httplowlevelclient.cpp b/src/apps/http/httplowlevelclient.cpp index a0c6f6e532..2f3b67d7b7 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) 2020, 2021, 2022, 2023 Volker Christian @@ -50,33 +51,33 @@ static web::http::client::ResponseParser* getResponseParser(core::socket::stream [](void) -> void { }, [](const std::string& httpVersion, const std::string& statusCode, const std::string& reason) -> void { - VLOG(0) << "++ Response: " << httpVersion << " " << statusCode << " " << reason; + snode::semantic::appLog().trace() << "++ Response: " << httpVersion << " " << statusCode << " " << reason; }, [](std::map& headers, std::map& cookies) -> void { - VLOG(0) << "++ Headers:"; + snode::semantic::appLog().trace() << "++ Headers:"; for (auto& [field, value] : headers) { - VLOG(0) << "++ " << field + " = " + value; + snode::semantic::appLog().trace() << "++ " << field + " = " + value; } - VLOG(0) << "++ Cookies:"; + snode::semantic::appLog().trace() << "++ Cookies:"; for (auto& [name, cookie] : cookies) { - VLOG(0) << "++ " + name + " = " + cookie.getValue(); + snode::semantic::appLog().trace() << "++ " + name + " = " + cookie.getValue(); for (auto& [option, value] : cookie.getOptions()) { - VLOG(0) << "++ " + option + " = " + value; + snode::semantic::appLog().trace() << "++ " + option + " = " + value; } } }, [](std::vector content) -> void { content.push_back(0); - VLOG(0) << "++ OnContent: "; // << content.data(); + snode::semantic::appLog().trace() << "++ OnContent: "; // << content.data(); }, [](web::http::client::ResponseParser& parser) -> void { - VLOG(0) << "++ OnParsed"; + snode::semantic::appLog().trace() << "++ OnParsed"; parser.reset(); }, [](int status, const std::string& reason) -> void { - VLOG(0) << "++ OnError: " + std::to_string(status) + " - " + reason; + snode::semantic::appLog().trace() << "++ OnError: " + std::to_string(status) + " - " + reason; }); return responseParser; @@ -92,10 +93,10 @@ class SimpleSocketProtocol : public core::socket::stream::SocketContext { ~SimpleSocketProtocol() override; void onConnected() override { - VLOG(0) << "SimpleSocketProtocol connected"; + snode::semantic::appLog().trace() << "SimpleSocketProtocol connected"; } void onDisconnected() override { - VLOG(0) << "SimpleSocketProtocol disconnected"; + snode::semantic::appLog().trace() << "SimpleSocketProtocol disconnected"; } std::size_t onReceivedFromPeer() override { @@ -103,12 +104,12 @@ class SimpleSocketProtocol : public core::socket::stream::SocketContext { } void onWriteError(int errnum) override { - VLOG(0) << "OnWriteError: " << errnum; + snode::semantic::appLog().trace() << "OnWriteError: " << errnum; shutdownRead(); } void onReadError(int errnum) override { - VLOG(0) << "OnReadError: " << errnum; + snode::semantic::appLog().trace() << "OnReadError: " << errnum; shutdownWrite(); } @@ -143,11 +144,11 @@ namespace tls { SocketClient client( "tls", [](SocketConnection* socketConnection) -> void { // onConnect - VLOG(0) << "OnConnect"; + snode::semantic::appLog().trace() << "OnConnect"; - VLOG(0) << "\tServer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tServer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\tClient: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tClient: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); /* Enable automatic hostname checks */ @@ -160,20 +161,20 @@ namespace tls { // } }, [](SocketConnection* socketConnection) -> void { // onConnected - VLOG(0) << "OnConnected"; + snode::semantic::appLog().trace() << "OnConnected"; X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(0) << " 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(0) << " 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(0) << " 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. @@ -188,7 +189,7 @@ namespace tls { #ifdef __clang__ #pragma clang diagnostic pop #endif - VLOG(0) << " Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << " Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { #ifdef __clang__ #pragma clang diagnostic push @@ -202,14 +203,14 @@ namespace tls { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - VLOG(0) << " SAN (URI): '" + subjectAltName; + snode::semantic::appLog().trace() << " 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(0) << " SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << " SAN (DNS): '" + subjectAltName; } else { - VLOG(0) << " SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << " SAN (Type): '" + std::to_string(generalName->type); } } #ifdef __clang__ @@ -222,16 +223,16 @@ namespace tls { #endif X509_free(server_cert); } else { - VLOG(0) << " 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) -> void { // onDisconnect - VLOG(0) << "OnDisconnect"; + snode::semantic::appLog().trace() << "OnDisconnect"; - VLOG(0) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); @@ -239,9 +240,9 @@ namespace tls { client.connect(remoteAddress, [](const SocketAddress& socketAddress, int err) -> void { if (err) { - PLOG(ERROR) << "Connect: " + std::to_string(err); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "Connect: " + std::to_string(err); } else { - VLOG(0) << "Connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "Connecting to " << socketAddress.toString(); } }); @@ -260,24 +261,24 @@ namespace legacy { SocketClient legacyClient( "legacy", [](SocketConnection* socketConnection) -> void { // OnConnect - VLOG(0) << "OnConnect"; + snode::semantic::appLog().trace() << "OnConnect"; - VLOG(0) << "\tServer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tServer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\tClient: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tClient: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); }, [](SocketConnection* socketConnection) -> void { // onConnected - VLOG(0) << "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) -> void { // onDisconnect - VLOG(0) << "OnDisconnect"; + snode::semantic::appLog().trace() << "OnDisconnect"; - VLOG(0) << "\tServer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tServer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\tClient: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tClient: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); }); @@ -285,9 +286,9 @@ namespace legacy { legacyClient.connect(remoteAddress, [](const SocketAddress& socketAddress, int err) -> void { if (err) { - PLOG(ERROR) << "Connect: " << std::to_string(err); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "Connect: " << std::to_string(err); } else { - VLOG(0) << "Connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "Connecting to " << socketAddress.toString(); } }); @@ -307,11 +308,11 @@ int main(int argc, char* argv[]) { legacyClient.connect(legacyRemoteAddress, [](const tls::SocketAddress& socketAddress, int errnum) -> void { // example.com:81 simulate connnect timeout if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c connecting to " << socketAddress.toString(); } }); @@ -321,11 +322,11 @@ int main(int argc, char* argv[]) { tlsClient.connect(tlsRemoteAddress, [](const tls::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c connecting to " << socketAddress.toString(); } }); } diff --git a/src/apps/http/httpserver.cpp b/src/apps/http/httpserver.cpp index c21eb76bf8..cc292290fd 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) 2020, 2021, 2022, 2023 Volker Christian @@ -56,11 +57,11 @@ int main(int argc, char* argv[]) { webApp.listen([&webApp](const WebApp::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << webApp.getConfig().getInstanceName() << " listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << webApp.getConfig().getInstanceName() << " listening on " << socketAddress.toString(); } }); @@ -94,9 +95,9 @@ int main(int argc, char* argv[]) { webApp.listen("/tmp/testme", 5, [](const WebApp::SocketAddress& socketAddress, int errnum) -> void { // titan #endif if (errnum != 0) { - PLOG(FATAL) << "listen"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Critical, errno) << "listen"; } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } #ifdef NET_TYPE diff --git a/src/apps/http/httpserverclientcert.cpp b/src/apps/http/httpserverclientcert.cpp index d377222695..d3bbd146fa 100644 --- a/src/apps/http/httpserverclientcert.cpp +++ b/src/apps/http/httpserverclientcert.cpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -46,11 +47,11 @@ int main(int argc, char* argv[]) { #endif webApp.listen([](const WebApp::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); @@ -84,9 +85,9 @@ int main(int argc, char* argv[]) { webApp.listen("/tmp/testme", 5, [](const WebApp::SocketAddress& socketAddress, int errnum) -> void { // titan #endif if (errnum != 0) { - PLOG(FATAL) << "listen"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Critical, errno) << "listen"; } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } #ifdef NET_TYPE diff --git a/src/apps/http/model/clients.h b/src/apps/http/model/clients.h index fb9573b467..c5e19f9065 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) 2020, 2021, 2022, 2023 Volker Christian @@ -60,30 +61,30 @@ namespace apps::http::legacy { request.start(); }, []([[maybe_unused]] Request& request, Response& response) -> void { - VLOG(0) << "-- OnResponse"; - VLOG(0) << " Status:"; - VLOG(0) << " " << response.httpVersion << " " << response.statusCode << " " << response.reason; + snode::semantic::appLog().trace() << "-- OnResponse"; + snode::semantic::appLog().trace() << " Status:"; + snode::semantic::appLog().trace() << " " << response.httpVersion << " " << response.statusCode << " " << response.reason; - VLOG(0) << " Headers:"; + snode::semantic::appLog().trace() << " Headers:"; for (const auto& [field, value] : response.headers) { - VLOG(0) << " " << field + " = " + value; + snode::semantic::appLog().trace() << " " << field + " = " + value; } - VLOG(0) << " Cookies:"; + snode::semantic::appLog().trace() << " Cookies:"; for (auto& [name, cookie] : response.cookies) { - VLOG(0) << " " + name + " = " + cookie.getValue(); + snode::semantic::appLog().trace() << " " + name + " = " + cookie.getValue(); for (auto& [option, value] : cookie.getOptions()) { - VLOG(0) << " " + option + " = " + value; + snode::semantic::appLog().trace() << " " + option + " = " + value; } } response.body.push_back(0); // make it a c-string - VLOG(0) << "Body:\n----------- start body -----------\n" << response.body.data() << "\n------------ end body ------------"; + snode::semantic::appLog().trace() << "Body:\n----------- start body -----------\n" << response.body.data() << "\n------------ end body ------------"; }, [](int status, const std::string& reason) -> void { - VLOG(0) << "-- OnResponseError"; - VLOG(0) << " Status: " << status; - VLOG(0) << " Reason: " << reason; + snode::semantic::appLog().trace() << "-- OnResponseError"; + snode::semantic::appLog().trace() << " Status: " << status; + snode::semantic::appLog().trace() << " Reason: " << reason; }); } @@ -109,37 +110,37 @@ namespace apps::http::tls { request.start(); }, []([[maybe_unused]] Request& request, Response& response) -> void { - VLOG(0) << "-- OnResponse"; - VLOG(0) << " Status:"; - VLOG(0) << " " << response.httpVersion << " " << response.statusCode << " " << response.reason; + snode::semantic::appLog().trace() << "-- OnResponse"; + snode::semantic::appLog().trace() << " Status:"; + snode::semantic::appLog().trace() << " " << response.httpVersion << " " << response.statusCode << " " << response.reason; - VLOG(0) << " Headers:"; + snode::semantic::appLog().trace() << " Headers:"; for (const auto& [field, value] : response.headers) { - VLOG(0) << " " << field + " = " + value; + snode::semantic::appLog().trace() << " " << field + " = " + value; } - VLOG(0) << " Cookies:"; + snode::semantic::appLog().trace() << " Cookies:"; for (auto& [name, cookie] : response.cookies) { - VLOG(0) << " " + name + " = " + cookie.getValue(); + snode::semantic::appLog().trace() << " " + name + " = " + cookie.getValue(); for (auto& [option, value] : cookie.getOptions()) { - VLOG(0) << " " + option + " = " + value; + snode::semantic::appLog().trace() << " " + option + " = " + value; } } response.body.push_back(0); // make it a c-string - VLOG(0) << "Body:\n----------- start body -----------\n" << response.body.data() << "\n------------ end body ------------"; + snode::semantic::appLog().trace() << "Body:\n----------- start body -----------\n" << response.body.data() << "\n------------ end body ------------"; }, [](int status, const std::string& reason) -> void { - VLOG(0) << "-- OnResponseError"; - VLOG(0) << " Status: " << status; - VLOG(0) << " Reason: " << reason; + snode::semantic::appLog().trace() << "-- OnResponseError"; + snode::semantic::appLog().trace() << " Status: " << status; + snode::semantic::appLog().trace() << " Reason: " << reason; }); client.setOnConnect([&client](SocketConnection* socketConnection) -> void { // onConnect - VLOG(0) << "OnConnect " << client.getConfig().getInstanceName(); + snode::semantic::appLog().trace() << "OnConnect " << client.getConfig().getInstanceName(); - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ @@ -153,20 +154,20 @@ namespace apps::http::tls { }); client.setOnConnected([&client](SocketConnection* socketConnection) -> void { // onConnected - VLOG(0) << "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) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(0) << "\tPeer certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); + snode::semantic::appLog().trace() << "\tPeer certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); - VLOG(0) << "\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(0) << "\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. @@ -181,7 +182,7 @@ namespace apps::http::tls { #ifdef __clang__ #pragma clang diagnostic pop #endif - VLOG(0) << "\t Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { #ifdef __clang__ #pragma clang diagnostic push @@ -195,14 +196,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(0) << "\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(0) << "\t SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (DNS): '" + subjectAltName; } else { - VLOG(0) << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << "\t SAN (Type): '" + std::to_string(generalName->type); } } #ifdef __clang__ @@ -215,15 +216,15 @@ namespace apps::http::tls { #endif X509_free(server_cert); } else { - VLOG(0) << "\tPeer certificate: no certificate"; + snode::semantic::appLog().trace() << "\tPeer certificate: no certificate"; } }); client.setOnDisconnect([&client](SocketConnection* socketConnection) -> void { // onDisconnect - VLOG(0) << "OnDisconnect " << client.getConfig().getInstanceName(); + snode::semantic::appLog().trace() << "OnDisconnect " << client.getConfig().getInstanceName(); - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }); return client; diff --git a/src/apps/http/model/servers.h b/src/apps/http/model/servers.h index 88923cc323..103c9daa6d 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) 2020, 2021, 2022, 2023 Volker Christian @@ -78,10 +79,10 @@ namespace apps::http::tls { WebApp webApp(name, getRouter(rootPath)); webApp.setOnConnect([&webApp](SocketConnection* socketConnection) -> void { // onConnect - VLOG(0) << "OnConnect " << webApp.getConfig().getInstanceName(); + snode::semantic::appLog().trace() << "OnConnect " << webApp.getConfig().getInstanceName(); - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ @@ -95,20 +96,20 @@ namespace apps::http::tls { }); webApp.setOnConnected([&webApp](SocketConnection* socketConnection) -> void { // onConnected - VLOG(0) << "OnConnected " << webApp.getConfig().getInstanceName(); + snode::semantic::appLog().trace() << "OnConnected " << webApp.getConfig().getInstanceName(); X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(0) << "\tPeer certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); + snode::semantic::appLog().trace() << "\tPeer certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); - VLOG(0) << "\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(0) << "\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. @@ -123,7 +124,7 @@ namespace apps::http::tls { #ifdef __clang__ #pragma clang diagnostic pop #endif - VLOG(0) << "\t Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { #ifdef __clang__ #pragma clang diagnostic push @@ -137,14 +138,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(0) << "\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(0) << "\t SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (DNS): '" + subjectAltName; } else { - VLOG(0) << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << "\t SAN (Type): '" + std::to_string(generalName->type); } } #ifdef __clang__ @@ -157,15 +158,15 @@ namespace apps::http::tls { #endif X509_free(server_cert); } else { - VLOG(0) << "\tPeer certificate: no certificate"; + snode::semantic::appLog().trace() << "\tPeer certificate: no certificate"; } }); webApp.setOnDisconnect([&webApp](SocketConnection* socketConnection) -> void { // onDisconnect - VLOG(0) << "OnDisconnect " << webApp.getConfig().getInstanceName(); + snode::semantic::appLog().trace() << "OnDisconnect " << webApp.getConfig().getInstanceName(); - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }); diff --git a/src/apps/jsonclient.cpp b/src/apps/jsonclient.cpp index af2047bb19..c57aee2735 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) 2020, 2021, 2022, 2023 Volker Christian @@ -43,7 +44,7 @@ int main(int argc, char* argv[]) { Client jsonClient( "legacy", [](Request& request) -> void { - VLOG(0) << "-- OnRequest"; + snode::semantic::appLog().trace() << "-- OnRequest"; request.method = "POST"; request.url = "/index.html"; request.type("application/json"); @@ -51,58 +52,58 @@ int main(int argc, char* argv[]) { request.send("{\"userId\":1,\"schnitzel\":\"good\",\"hungry\":false}"); }, []([[maybe_unused]] Request& request, Response& response) -> void { - VLOG(0) << "-- OnResponse"; - VLOG(0) << " Status:"; - VLOG(0) << " " << response.httpVersion; - VLOG(0) << " " << response.statusCode; - VLOG(0) << " " << response.reason; + snode::semantic::appLog().trace() << "-- OnResponse"; + snode::semantic::appLog().trace() << " Status:"; + snode::semantic::appLog().trace() << " " << response.httpVersion; + snode::semantic::appLog().trace() << " " << response.statusCode; + snode::semantic::appLog().trace() << " " << response.reason; - VLOG(0) << " Headers:"; + snode::semantic::appLog().trace() << " Headers:"; for (auto& [field, value] : response.headers) { - VLOG(0) << " " << field + " = " + value; + snode::semantic::appLog().trace() << " " << field + " = " + value; } - VLOG(0) << " Cookies:"; + snode::semantic::appLog().trace() << " Cookies:"; for (auto& [name, cookie] : response.cookies) { - VLOG(0) << " " + name + " = " + cookie.getValue(); + snode::semantic::appLog().trace() << " " + name + " = " + cookie.getValue(); for (auto& [option, value] : cookie.getOptions()) { - VLOG(0) << " " + option + " = " + value; + snode::semantic::appLog().trace() << " " + option + " = " + value; } } response.body.push_back(0); - VLOG(0) << " Body:\n----------- start body -----------" << response.body.data() << "\n------------ end body ------------"; + snode::semantic::appLog().trace() << " Body:\n----------- start body -----------" << response.body.data() << "\n------------ end body ------------"; }, [](int status, const std::string& reason) -> void { - VLOG(0) << "-- OnResponseError"; - VLOG(0) << " Status: " << status; - VLOG(0) << " Reason: " << reason; + snode::semantic::appLog().trace() << "-- OnResponseError"; + snode::semantic::appLog().trace() << " Status: " << status; + snode::semantic::appLog().trace() << " Reason: " << reason; }); jsonClient.connect("localhost", 8080, [](const SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c connecting to " << socketAddress.toString(); } }); jsonClient.connect("localhost", 8080, [](const SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c connecting to " << socketAddress.toString(); } }); /* jsonClient.post("localhost", 8080, "/index.html", "{\"userId\":1,\"schnitzel\":\"good\",\"hungry\":false}", [](int err) -> void { 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 c076f03254..51cb42ab29 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) 2020, 2021, 2022, 2023 Volker Christian @@ -44,11 +45,11 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); @@ -58,10 +59,10 @@ int main(int argc, char* argv[]) { req.getAttribute( [&jsonString](json& json) -> void { jsonString = json.dump(4); - VLOG(0) << "Application received body: " << jsonString; + snode::semantic::appLog().trace() << "Application received body: " << jsonString; }, [](const std::string& key) -> void { - VLOG(0) << key << " attribute not found"; + snode::semantic::appLog().trace() << key << " attribute not found"; }); res.send(jsonString); diff --git a/src/apps/oauth2/authorization_server/AuthorizationServer.cpp b/src/apps/oauth2/authorization_server/AuthorizationServer.cpp index 84ba0e1094..8220ba8143 100644 --- a/src/apps/oauth2/authorization_server/AuthorizationServer.cpp +++ b/src/apps/oauth2/authorization_server/AuthorizationServer.cpp @@ -1,3 +1,4 @@ +#include #include "database/mariadb/MariaDBClient.h" #include "database/mariadb/MariaDBCommandSequence.h" #include "express/legacy/in/WebApp.h" @@ -73,17 +74,17 @@ int main(int argc, char* argv[]) { [&req, &res, next, queryClientId](const MYSQL_ROW row) -> void { if (row != nullptr) { if (std::stoi(row[0]) > 0) { - VLOG(0) << "Valid client id '" << queryClientId << "'"; - VLOG(0) << "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(0) << "Invalid client id '" << queryClientId << "'"; + snode::semantic::appLog().trace() << "Invalid client id '" << queryClientId << "'"; res.sendStatus(401); } } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); } else { @@ -101,14 +102,14 @@ int main(int argc, char* argv[]) { std::string paramScope{req.query("scope")}; std::string paramState{req.query("state")}; - VLOG(0) << "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(0) << "Auth invalid, sending Bad Request"; + snode::semantic::appLog().trace() << "Auth invalid, sending Bad Request"; res.sendStatus(400); return; } @@ -117,10 +118,10 @@ int main(int argc, char* argv[]) { db.exec( "update client set redirect_uri = '" + paramRedirectUri + "' where uuid = '" + paramClientId + "'", [paramRedirectUri]() -> void { - VLOG(0) << "Database: Set redirect_uri to " << paramRedirectUri; + snode::semantic::appLog().trace() << "Database: Set redirect_uri to " << paramRedirectUri; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; }); } @@ -128,10 +129,10 @@ int main(int argc, char* argv[]) { db.exec( "update client set scope = '" + paramScope + "' where uuid = '" + paramClientId + "'", [paramScope]() -> void { - VLOG(0) << "Database: Set scope to " << paramScope; + snode::semantic::appLog().trace() << "Database: Set scope to " << paramScope; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; }); } @@ -139,14 +140,14 @@ int main(int argc, char* argv[]) { db.exec( "update client set state = '" + paramState + "' where uuid = '" + paramClientId + "'", [paramState]() -> void { - VLOG(0) << "Database: Set state to " << paramState; + snode::semantic::appLog().trace() << "Database: Set state to " << paramState; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; }); } - VLOG(0) << "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); @@ -156,7 +157,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) -> void { if (ret != 0) { - PLOG(ERROR) << req.url; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << req.url; } }); }); @@ -195,7 +196,7 @@ int main(int argc, char* argv[]) { []() -> void { }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }) .query( @@ -220,24 +221,24 @@ int main(int argc, char* argv[]) { res.set("Access-Control-Allow-Origin", "*"); nlohmann::json responseJson = {{"redirect_uri", clientRedirectUri}}; std::string responseJsonString{responseJson.dump(4)}; - VLOG(0) << "Sending json reponse: " << responseJsonString; + snode::semantic::appLog().trace() << "Sending json reponse: " << responseJsonString; res.send(responseJsonString); }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); } } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); }, @@ -249,11 +250,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(0) << "GrandType: " << queryGrantType; + snode::semantic::appLog().trace() << "GrandType: " << queryGrantType; auto queryCode = req.query("code"); - VLOG(0) << "Code: " << queryCode; + snode::semantic::appLog().trace() << "Code: " << queryCode; auto queryRedirectUri = req.query("redirect_uri"); - VLOG(0) << "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; @@ -312,7 +313,7 @@ int main(int argc, char* argv[]) { []() -> void { }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }) .query( @@ -329,13 +330,13 @@ int main(int argc, char* argv[]) { []() -> void { }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }) .exec( @@ -348,7 +349,7 @@ int main(int argc, char* argv[]) { []() -> void { }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }) .query( @@ -372,26 +373,26 @@ int main(int argc, char* argv[]) { res.send(jsonResponseString); }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); } } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); }); @@ -399,13 +400,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(0) << "ClientId: " << queryClientId; + snode::semantic::appLog().trace() << "ClientId: " << queryClientId; auto queryGrantType = req.query("grant_type"); - VLOG(0) << "GrandType: " << queryGrantType; + snode::semantic::appLog().trace() << "GrandType: " << queryGrantType; auto queryRefreshToken = req.query("refresh_token"); - VLOG(0) << "RefreshToken: " << queryRefreshToken; + snode::semantic::appLog().trace() << "RefreshToken: " << queryRefreshToken; auto queryState = req.query("state"); - VLOG(0) << "State: " << queryState; + snode::semantic::appLog().trace() << "State: " << queryState; if (queryGrantType.length() == 0) { res.status(400).send("Missing query parameter 'grant_type'"); return; @@ -446,7 +447,7 @@ int main(int argc, char* argv[]) { []() -> void { }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }) .query( @@ -466,34 +467,34 @@ int main(int argc, char* argv[]) { res.send(responseJson.dump(4)); }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); }); router.post("/token/validate", [&db] APPLICATION(req, res) { - VLOG(0) << "POST /token/validate"; + snode::semantic::appLog().trace() << "POST /token/validate"; req.getAttribute([&res, &db](nlohmann::json& jsonBody) -> void { if (!jsonBody.contains("access_token")) { - VLOG(0) << "Missing 'access_token' in json"; + snode::semantic::appLog().trace() << "Missing 'access_token' in json"; res.status(500).send("Missing 'access_token' in json"); return; } std::string jsonAccessToken{jsonBody["access_token"]}; if (!jsonBody.contains("client_id")) { - VLOG(0) << "Missing 'client_id' in json"; + snode::semantic::appLog().trace() << "Missing 'client_id' in json"; res.status(500).send("Missing 'client_id' in json"); return; } @@ -512,17 +513,17 @@ int main(int argc, char* argv[]) { if (row != nullptr) { if (std::stoi(row[0]) == 0) { nlohmann::json errorJson = {{"error", "Invalid access token"}}; - VLOG(0) << "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(0) << "Sending 200: Valid access token '" << jsonAccessToken << ""; + snode::semantic::appLog().trace() << "Sending 200: Valid access token '" << jsonAccessToken << ""; nlohmann::json successJson = {{"success", "Valid access token"}}; res.status(200).send(successJson.dump(4)); } } }, [&res](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Database error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Database error: " << errorString << " : " << errorNumber; res.sendStatus(500); }); }); diff --git a/src/apps/oauth2/client_app/ClientApp.cpp b/src/apps/oauth2/client_app/ClientApp.cpp index 6a984fbb90..aef4b0482c 100644 --- a/src/apps/oauth2/client_app/ClientApp.cpp +++ b/src/apps/oauth2/client_app/ClientApp.cpp @@ -1,3 +1,4 @@ +#include #include "express/legacy/in/WebApp.h" #include "express/middleware/StaticMiddleware.h" #include "log/Logger.h" @@ -14,7 +15,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) -> void { if (ret != 0) { - PLOG(ERROR) << req.url; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << req.url; } }); /* @@ -26,7 +27,7 @@ int main(int argc, char* argv[]) { } tokenRequestUri += "&client_id=911a821a-ea2d-11ec-8e2e-08002771075f"; tokenRequestUri += "&redirect_uri=http://localhost:8081/oauth2"; - VLOG(0) << "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); */ } diff --git a/src/apps/oauth2/resource_server/ResourceServer.cpp b/src/apps/oauth2/resource_server/ResourceServer.cpp index c751d390f3..455abb39f4 100644 --- a/src/apps/oauth2/resource_server/ResourceServer.cpp +++ b/src/apps/oauth2/resource_server/ResourceServer.cpp @@ -1,3 +1,4 @@ +#include #include "express/legacy/in/WebApp.h" #include "express/middleware/JsonMiddleware.h" #include "log/Logger.h" @@ -22,7 +23,7 @@ int main(int argc, char* argv[]) { std::string queryAccessToken{req.query("access_token")}; std::string queryClientId{req.query("client_id")}; if (queryAccessToken.empty() || queryClientId.empty()) { - VLOG(0) << "Missing access_token or client_id in body"; + snode::semantic::appLog().trace() << "Missing access_token or client_id in body"; res.sendStatus(401); return; } @@ -30,29 +31,29 @@ int main(int argc, char* argv[]) { web::http::legacy::in::Client legacyClient( [](web::http::legacy::in::Client::SocketConnection* socketConnection) -> void { - VLOG(0) << "OnConnect"; + snode::semantic::appLog().trace() << "OnConnect"; - VLOG(0) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\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) -> void { - VLOG(0) << "OnConnected"; + snode::semantic::appLog().trace() << "OnConnected"; }, [queryAccessToken, queryClientId](web::http::client::Request& request) -> void { - VLOG(0) << "OnRequestBegin"; + snode::semantic::appLog().trace() << "OnRequestBegin"; request.url = "/oauth2/token/validate?client_id=" + queryClientId; request.method = "POST"; - VLOG(0) << "ClientId: " << queryClientId; - VLOG(0) << "AcceessToken: " << queryAccessToken; + snode::semantic::appLog().trace() << "ClientId: " << queryClientId; + snode::semantic::appLog().trace() << "AcceessToken: " << queryAccessToken; nlohmann::json requestJson = {{"access_token", queryAccessToken}, {"client_id", queryClientId}}; std::string requestJsonString{requestJson.dump(4)}; request.send(requestJsonString); }, [&res]([[maybe_unused]] web::http::client::Request& request, web::http::client::Response& response) -> void { - VLOG(0) << "OnResponse"; + snode::semantic::appLog().trace() << "OnResponse"; response.body.push_back(0); - VLOG(0) << "Response: " << response.body.data(); + snode::semantic::appLog().trace() << "Response: " << response.body.data(); if (std::stoi(response.statusCode) != 200) { nlohmann::json errorJson = {{"error", "Invalid access token"}}; res.status(401).send(errorJson.dump(4)); @@ -62,16 +63,16 @@ int main(int argc, char* argv[]) { } }, [](int status, const std::string& reason) -> void { - VLOG(0) << "OnResponseError"; - VLOG(0) << " Status: " << status; - VLOG(0) << " Reason: " << reason; + snode::semantic::appLog().trace() << "OnResponseError"; + snode::semantic::appLog().trace() << " Status: " << status; + snode::semantic::appLog().trace() << " Reason: " << reason; }, [](web::http::legacy::in::Client::SocketConnection* socketConnection) -> void { - VLOG(0) << "OnDisconnect"; + snode::semantic::appLog().trace() << "OnDisconnect"; - VLOG(0) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::semantic::appLog().trace() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::semantic::appLog().trace() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); legacyClient.connect( @@ -80,9 +81,9 @@ int main(int argc, char* argv[]) { [](const web::http::legacy::in::Client::SocketAddress& socketAddress, int err) -> void { if (err != 0) { - PLOG(ERROR) << "OnError: " << err; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << err; } else { - VLOG(0) << "Resource server client connecting to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "Resource server client connecting to " << socketAddress.toString(); } }); }); diff --git a/src/apps/testbasicauthentication.cpp b/src/apps/testbasicauthentication.cpp index d5e678f7c3..ee9fe27cbb 100644 --- a/src/apps/testbasicauthentication.cpp +++ b/src/apps/testbasicauthentication.cpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -67,11 +68,11 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const legacy::in6::WebApp::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); @@ -95,11 +96,11 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const legacy::in6::WebApp::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); } diff --git a/src/apps/testparsers.cpp b/src/apps/testparsers.cpp index 18b3b3c5a5..d22549dd0e 100644 --- a/src/apps/testparsers.cpp +++ b/src/apps/testparsers.cpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -47,31 +48,31 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) { int httpMajor, int httpMinor, const std::map& queries) -> void { - VLOG(0) << "++ Request: " << method << " " << originalUrl << " " + snode::semantic::appLog().trace() << "++ Request: " << method << " " << originalUrl << " " << " " << httpVersion << " " << httpMajor << " " << httpMinor; for (const auto& [queryField, queryValue] : queries) { - VLOG(0) << "++ Query: " << queryField << " = " << queryValue; + snode::semantic::appLog().trace() << "++ Query: " << queryField << " = " << queryValue; } }, [](std::map& header, std::map& cookies) -> void { - VLOG(0) << "++ Header: "; + snode::semantic::appLog().trace() << "++ Header: "; for (auto& [headerField, headerFieldValue] : header) { - VLOG(0) << "++ " << headerField << " = " << headerFieldValue; + snode::semantic::appLog().trace() << "++ " << headerField << " = " << headerFieldValue; } - VLOG(0) << "++ Cookie: "; + snode::semantic::appLog().trace() << "++ Cookie: "; for (auto& [cookieName, cookieValue] : cookies) { - VLOG(0) << "++ " << cookieName << " = " << cookieValue; + snode::semantic::appLog().trace() << "++ " << cookieName << " = " << cookieValue; } }, [](std::vector& content) -> void { content.push_back(0); - VLOG(0) << content.data(); + snode::semantic::appLog().trace() << content.data(); }, []() -> void { - VLOG(0) << "++ OnParsed"; + snode::semantic::appLog().trace() << "++ OnParsed"; }, [](int status, const std::string& reason) -> void { - VLOG(0) << "++ OnError: " << status << " : " << reason; + snode::semantic::appLog().trace() << "++ OnError: " << status << " : " << reason; }); std::string httpRequest = "GET /admin/new/index.html?hihihi=3343&query=2324#fragment HTTP/1.1\r\n" @@ -86,16 +87,16 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) { "\r\n" "juhuhuhu"; - VLOG(0) << "=================================="; - VLOG(0) << httpRequest; - VLOG(0) << "----------------------------------"; + snode::semantic::appLog().trace() << "=================================="; + snode::semantic::appLog().trace() << httpRequest; + snode::semantic::appLog().trace() << "----------------------------------"; requestParser.parse(); requestParser.reset(); - VLOG(0) << "=================================="; - VLOG(0) << httpRequest; - VLOG(0) << "----------------------------------"; + snode::semantic::appLog().trace() << "=================================="; + snode::semantic::appLog().trace() << httpRequest; + snode::semantic::appLog().trace() << "----------------------------------"; requestParser.parse(); requestParser.reset(); @@ -105,32 +106,32 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) { [](void) -> void { }, [](const std::string& httpVersion, const std::string& statusCode, const std::string& reason) -> void { - VLOG(0) << "++ Response: " << httpVersion << " " << statusCode << " " << reason; + snode::semantic::appLog().trace() << "++ Response: " << httpVersion << " " << statusCode << " " << reason; }, [](std::map& headers, std::map& cookies) -> void { - VLOG(0) << "++ Headers:"; + snode::semantic::appLog().trace() << "++ Headers:"; for (auto& [field, value] : headers) { - VLOG(0) << "++ " << field + " = " + value; + snode::semantic::appLog().trace() << "++ " << field + " = " + value; } - VLOG(0) << "++ Cookies:"; + snode::semantic::appLog().trace() << "++ Cookies:"; for (auto& [name, cookie] : cookies) { - VLOG(0) << "++ " + name + " = " + cookie.getValue(); + snode::semantic::appLog().trace() << "++ " + name + " = " + cookie.getValue(); for (auto& [option, value] : cookie.getOptions()) { - VLOG(0) << "++ " + option + " = " + value; + snode::semantic::appLog().trace() << "++ " + option + " = " + value; } } }, [](std::vector& content) -> void { content.push_back(0); - VLOG(0) << content.data(); + snode::semantic::appLog().trace() << content.data(); }, [](client::ResponseParser& parser) -> void { - VLOG(0) << "++ OnParsed"; + snode::semantic::appLog().trace() << "++ OnParsed"; parser.reset(); }, [](int status, const std::string& reason) -> void { - VLOG(0) << "++ OnError: " + std::to_string(status) + " - " + reason; + snode::semantic::appLog().trace() << "++ OnError: " + std::to_string(status) + " - " + reason; }); std::string httpResponse = "HTTP/1.1 200 OK\r\n" @@ -141,15 +142,15 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) { "\r\n" "juhuhuhu"; - VLOG(0) << "=================================="; - VLOG(0) << httpResponse; - VLOG(0) << "----------------------------------"; + snode::semantic::appLog().trace() << "=================================="; + snode::semantic::appLog().trace() << httpResponse; + snode::semantic::appLog().trace() << "----------------------------------"; responseParser.parse(); responseParser.reset(); - VLOG(0) << "=================================="; - VLOG(0) << httpResponse; - VLOG(0) << "----------------------------------"; + snode::semantic::appLog().trace() << "=================================="; + snode::semantic::appLog().trace() << httpResponse; + snode::semantic::appLog().trace() << "----------------------------------"; responseParser.parse(); responseParser.reset(); diff --git a/src/apps/testpipe.cpp b/src/apps/testpipe.cpp index d787055b24..53fbe91812 100644 --- a/src/apps/testpipe.cpp +++ b/src/apps/testpipe.cpp @@ -1,3 +1,4 @@ +#include #include "core/SNodeC.h" #include "core/pipe/Pipe.h" #include "core/pipe/PipeSink.h" @@ -15,28 +16,28 @@ int main(int argc, char* argv[]) { []([[maybe_unused]] core::pipe::PipeSource& pipeSource, [[maybe_unused]] core::pipe::PipeSink& pipeSink) -> void { pipeSink.setOnData([&pipeSource](const char* junk, std::size_t junkLen) -> void { std::string string(junk, junkLen); - VLOG(0) << "Pipe Data: " << string; + snode::semantic::appLog().trace() << "Pipe Data: " << string; pipeSource.send(junk, junkLen); // pipeSink.disable(); // pipeSource.disable(); }); pipeSink.setOnEof([]() -> void { - VLOG(0) << "Pipe EOF"; + snode::semantic::appLog().trace() << "Pipe EOF"; }); pipeSink.setOnError([]([[maybe_unused]] int errnum) -> void { - PLOG(ERROR) << "PipeSink"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "PipeSink"; }); pipeSource.setOnError([]([[maybe_unused]] int errnum) -> void { - PLOG(ERROR) << "PipeSource"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "PipeSource"; }); pipeSource.send("Hello World!"); }, []([[maybe_unused]] int errnum) -> void { - 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 9f0ed2891e..ba8684942f 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) 2020, 2021, 2022, 2023 Volker Christian @@ -66,11 +67,11 @@ int main(int argc, char* argv[]) { }); legacyApp.post("/", [] APPLICATION(req, res) { - VLOG(0) << "Content-Type: " << req.get("Content-Type"); - VLOG(0) << "Content-Length: " << req.get("Content-Length"); + snode::semantic::appLog().trace() << "Content-Type: " << req.get("Content-Type"); + snode::semantic::appLog().trace() << "Content-Length: " << req.get("Content-Length"); req.body.push_back(0); - VLOG(0) << req.body.data(); + snode::semantic::appLog().trace() << req.body.data(); res.send("" " " @@ -85,9 +86,9 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const LegacySocketAddress& socketAddress, int errnum) -> void { if (errnum != 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "LegacyWebApp listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "LegacyWebApp listening on " << socketAddress.toString(); } }); @@ -105,9 +106,9 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const TLSSocketAddress& socketAddress, int errnum) -> void { if (errnum != 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "TLSWebApp listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "TLSWebApp listening on " << socketAddress.toString(); } }); diff --git a/src/apps/testregex.cpp b/src/apps/testregex.cpp index 5dfeb5998b..c392e68225 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) 2020, 2021, 2022, 2023 Volker Christian @@ -48,11 +49,11 @@ Router router(database::mariadb::MariaDBClient& db) { .get( "/query/:userId", [] MIDDLEWARE(req, res, next) { - VLOG(0) << "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(0) << "UserId: " << req.params["userId"]; + snode::semantic::appLog().trace() << "UserId: " << req.params["userId"]; std::string userId = req.params["userId"]; req.setAttribute(std::string()); @@ -103,29 +104,29 @@ Router router(database::mariadb::MariaDBClient& db) { " \n" "\n")); }); - VLOG(0) << "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) -> void { - VLOG(0) << "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(0) << "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(0) << "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(0) << "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(0) << "SendResult"; + snode::semantic::appLog().trace() << "SendResult"; req.getAttribute( [&res](std::string& table) -> void { @@ -136,9 +137,9 @@ Router router(database::mariadb::MariaDBClient& db) { }); }); router.get("/account/:userId(\\d*)/:userName", [&db] APPLICATION(req, res) { // http://localhost:8080/account/123/perfectNDSgroup - VLOG(0) << "Show account of"; - VLOG(0) << "UserId: " << req.params["userId"]; - VLOG(0) << "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"]; std::string response = "" " " @@ -163,18 +164,18 @@ Router router(database::mariadb::MariaDBClient& db) { db.exec( "INSERT INTO `snodec`(`username`, `password`) VALUES ('" + userId + "','" + userName + "')", [userId, userName](void) -> void { - VLOG(0) << "Inserted: -> " << userId << " - " << userName; + snode::semantic::appLog().trace() << "Inserted: -> " << userId << " - " << userName; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "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(0) << "Testing Regex"; - VLOG(0) << "Regex1: " << req.params["testRegex1"]; - VLOG(0) << "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"]; std::string response = "" " " @@ -196,9 +197,9 @@ Router router(database::mariadb::MariaDBClient& db) { res.send(response); }); router.get("/search/:search", [] APPLICATION(req, res) { // http://localhost:8080/search/buxtehude123 - VLOG(0) << "Show Search of"; - VLOG(0) << "Search: " << req.params["search"]; - VLOG(0) << "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"]); }); @@ -237,26 +238,26 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const legacy::in::WebApp::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); legacyApp.setOnConnect([](legacy::in::WebApp::SocketConnection* socketConnection) -> void { - VLOG(0) << "OnConnect:"; + snode::semantic::appLog().trace() << "OnConnect:"; - VLOG(0) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\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) -> void { - VLOG(0) << "OnDisconnect:"; + snode::semantic::appLog().trace() << "OnDisconnect:"; - VLOG(0) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\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"); @@ -265,37 +266,37 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const tls::in::WebApp::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); tlsApp.setOnConnect([](tls::in::WebApp::SocketConnection* socketConnection) -> void { - VLOG(0) << "OnConnect:"; + snode::semantic::appLog().trace() << "OnConnect:"; - VLOG(0) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\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(0) << "OnConnected:"; + snode::semantic::appLog().trace() << "OnConnected:"; X509* client_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (client_cert != nullptr) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - VLOG(0) << "\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(0) << "\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(0) << "\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. @@ -310,7 +311,7 @@ int main(int argc, char* argv[]) { #ifdef __clang__ #pragma clang diagnostic pop #endif - VLOG(0) << "\t Subject alternative name count: " << altNameCount; + snode::semantic::appLog().trace() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { #ifdef __clang__ #pragma clang diagnostic push @@ -324,14 +325,14 @@ int main(int argc, char* argv[]) { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - VLOG(0) << "\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(0) << "\t SAN (DNS): '" + subjectAltName; + snode::semantic::appLog().trace() << "\t SAN (DNS): '" + subjectAltName; } else { - VLOG(0) << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::semantic::appLog().trace() << "\t SAN (Type): '" + std::to_string(generalName->type); } } #ifdef __clang__ @@ -344,15 +345,15 @@ int main(int argc, char* argv[]) { #endif X509_free(client_cert); } else { - VLOG(0) << "\tClient certificate: no certificate"; + snode::semantic::appLog().trace() << "\tClient certificate: no certificate"; } }); tlsApp.setOnDisconnect([](tls::in::WebApp::SocketConnection* socketConnection) -> void { - VLOG(0) << "OnDisconnect:"; + snode::semantic::appLog().trace() << "OnDisconnect:"; - VLOG(0) << "\tServer: " + socketConnection->getRemoteAddress().toString(); - VLOG(0) << "\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/verysimpleserver.cpp b/src/apps/verysimpleserver.cpp index 635aa9eb68..8625de2f2c 100644 --- a/src/apps/verysimpleserver.cpp +++ b/src/apps/verysimpleserver.cpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -41,11 +42,11 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const LegacySocketAddress& socketAddress, int errnum) { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); @@ -63,11 +64,11 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const TLSSocketAddress& socketAddress, int errnum) { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); diff --git a/src/apps/vhostserver.cpp b/src/apps/vhostserver.cpp index 636cf51b94..3926206569 100644 --- a/src/apps/vhostserver.cpp +++ b/src/apps/vhostserver.cpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -67,11 +68,11 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const legacy::in6::WebApp::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); @@ -94,11 +95,11 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const legacy::in6::WebApp::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); diff --git a/src/apps/warema-jalousien.cpp b/src/apps/warema-jalousien.cpp index 1aefc93e7c..3693516aca 100644 --- a/src/apps/warema-jalousien.cpp +++ b/src/apps/warema-jalousien.cpp @@ -1,3 +1,4 @@ +#include #ifndef DOXYGEN_SHOULD_SKIP_THIS #include "express/legacy/in/WebApp.h" @@ -28,8 +29,8 @@ int main(int argc, char* argv[]) { // tls::WebApp wa; webApp.get("/jalousien/:id", [] APPLICATION(req, res) { - VLOG(0) << "Param: " << req.param("id"); - VLOG(0) << "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")]; @@ -57,11 +58,11 @@ int main(int argc, char* argv[]) { webApp.listen(8080, [](const legacy::in::WebApp::SocketAddress& socketAddress, int errnum) -> void { if (errnum < 0) { - PLOG(ERROR) << "OnError"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError"; } else if (errnum > 0) { - PLOG(ERROR) << "OnError: " << socketAddress.toString(); + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << socketAddress.toString(); } else { - VLOG(0) << "snode.c listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "snode.c listening on " << socketAddress.toString(); } }); diff --git a/src/apps/websocket/echoclient.cpp b/src/apps/websocket/echoclient.cpp index 0527fa4a5e..914e45ed44 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) 2020, 2021, 2022, 2023 Volker Christian @@ -41,46 +42,46 @@ int main(int argc, char* argv[]) { web::http::legacy::in::Client legacyClient( "legacy", [](web::http::client::Request& request) -> void { - VLOG(0) << "OnRequestBegin"; + snode::semantic::appLog().trace() << "OnRequestBegin"; request.set("Sec-WebSocket-Protocol", "test, echo"); request.upgrade("/ws/", "websocket"); }, [](web::http::client::Request& request, web::http::client::Response& response) -> void { - VLOG(0) << "OnResponse"; - VLOG(0) << " Status:"; - VLOG(0) << " " << response.httpVersion << " " << response.statusCode << " " << response.reason; + snode::semantic::appLog().trace() << "OnResponse"; + snode::semantic::appLog().trace() << " Status:"; + snode::semantic::appLog().trace() << " " << response.httpVersion << " " << response.statusCode << " " << response.reason; - VLOG(0) << " Headers:"; + snode::semantic::appLog().trace() << " Headers:"; for (const auto& [field, value] : response.headers) { - VLOG(0) << " " << field + " = " + value; + snode::semantic::appLog().trace() << " " << field + " = " + value; } - VLOG(0) << " Cookies:"; + snode::semantic::appLog().trace() << " Cookies:"; for (auto& [name, cookie] : response.cookies) { - VLOG(0) << " " + name + " = " + cookie.getValue(); + snode::semantic::appLog().trace() << " " + name + " = " + cookie.getValue(); for (const auto& [option, value] : cookie.getOptions()) { - VLOG(0) << " " + option + " = " + value; + snode::semantic::appLog().trace() << " " + option + " = " + value; } } response.body.push_back(0); // make it a c-string - VLOG(0) << "Body:\n----------- start body -----------\n" << response.body.data() << "\n------------ end body ------------"; + snode::semantic::appLog().trace() << "Body:\n----------- start body -----------\n" << response.body.data() << "\n------------ end body ------------"; response.upgrade(request); }, [](int status, const std::string& reason) -> void { - VLOG(0) << "OnResponseError"; - VLOG(0) << " Status: " << status; - VLOG(0) << " Reason: " << reason; + snode::semantic::appLog().trace() << "OnResponseError"; + snode::semantic::appLog().trace() << " Status: " << status; + snode::semantic::appLog().trace() << " Reason: " << reason; }); legacyClient.connect([](const LegacySocketAddress& socketAddress, int err) -> void { if (err != 0) { - PLOG(ERROR) << "OnError: " << err; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << err; } else { - VLOG(0) << "wsechoclient connected to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "wsechoclient connected to " << socketAddress.toString(); } }); // Connection:keep-alive\r\n\r\n" @@ -89,46 +90,46 @@ int main(int argc, char* argv[]) { web::http::tls::in::Client tlsClient( "tls", [](web::http::client::Request& request) -> void { - VLOG(0) << "OnRequestBegin"; + snode::semantic::appLog().trace() << "OnRequestBegin"; request.set("Sec-WebSocket-Protocol", "test, echo"); request.upgrade("/ws/", "websocket"); }, [](web::http::client::Request& request, web::http::client::Response& response) -> void { - VLOG(0) << "OnResponse"; - VLOG(0) << " Status:"; - VLOG(0) << " " << response.httpVersion << " " << response.statusCode << " " << response.reason; + snode::semantic::appLog().trace() << "OnResponse"; + snode::semantic::appLog().trace() << " Status:"; + snode::semantic::appLog().trace() << " " << response.httpVersion << " " << response.statusCode << " " << response.reason; - VLOG(0) << " Headers:"; + snode::semantic::appLog().trace() << " Headers:"; for (auto& [field, value] : response.headers) { - VLOG(0) << " " << field + " = " + value; + snode::semantic::appLog().trace() << " " << field + " = " + value; } - VLOG(0) << " Cookies:"; + snode::semantic::appLog().trace() << " Cookies:"; for (auto& [name, cookie] : response.cookies) { - VLOG(0) << " " + name + " = " + cookie.getValue(); + snode::semantic::appLog().trace() << " " + name + " = " + cookie.getValue(); for (auto& [option, value] : cookie.getOptions()) { - VLOG(0) << " " + option + " = " + value; + snode::semantic::appLog().trace() << " " + option + " = " + value; } } response.body.push_back(0); // make it a c-string - VLOG(0) << "Body:\n----------- start body -----------\n" << response.body.data() << "\n------------ end body ------------"; + snode::semantic::appLog().trace() << "Body:\n----------- start body -----------\n" << response.body.data() << "\n------------ end body ------------"; response.upgrade(request); }, [](int status, const std::string& reason) -> void { - VLOG(0) << "OnResponseError"; - VLOG(0) << " Status: " << status; - VLOG(0) << " Reason: " << reason; + snode::semantic::appLog().trace() << "OnResponseError"; + snode::semantic::appLog().trace() << " Status: " << status; + snode::semantic::appLog().trace() << " Reason: " << reason; }); tlsClient.connect([](const TLSSocketAddress& socketAddress, int err) -> void { if (err != 0) { - PLOG(ERROR) << "OnError: " << err; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << err; } else { - VLOG(0) << "wsechoclient connected to " << socketAddress.toString(); + snode::semantic::appLog().trace() << "wsechoclient connected to " << socketAddress.toString(); } }); // Connection:keep-alive\r\n\r\n" } diff --git a/src/apps/websocket/echoserver.cpp b/src/apps/websocket/echoserver.cpp index e0cefee4f0..3d6e2484fc 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) 2020, 2021, 2022, 2023 Volker Christian @@ -37,10 +38,10 @@ int main(int argc, char* argv[]) { req.url = "/wstest.html"; } - VLOG(0) << 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](int ret) -> void { if (ret != 0) { - PLOG(ERROR) << req.url; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << req.url; } }); }); @@ -48,18 +49,18 @@ int main(int argc, char* argv[]) { legacyApp.get("/ws", [](Request& req, Response& res) -> void { std::string uri = req.originalUrl; - VLOG(1) << "OriginalUri: " << uri; - VLOG(1) << "Uri: " << req.url; + snode::semantic::appLog().trace() << "OriginalUri: " << uri; + snode::semantic::appLog().trace() << "Uri: " << req.url; - VLOG(1) << "Host: " << req.get("host"); - VLOG(1) << "Connection: " << req.get("connection"); - VLOG(1) << "Origin: " << req.get("origin"); - VLOG(1) << "Sec-WebSocket-Protocol: " << req.get("sec-websocket-protocol"); - VLOG(1) << "sec-web-socket-extensions: " << req.get("sec-websocket-extensions"); - VLOG(1) << "sec-websocket-key: " << req.get("sec-websocket-key"); - VLOG(1) << "sec-websocket-version: " << req.get("sec-websocket-version"); - VLOG(1) << "upgrade: " << req.get("upgrade"); - VLOG(1) << "user-agent: " << req.get("user-agent"); + snode::semantic::appLog().trace() << "Host: " << req.get("host"); + snode::semantic::appLog().trace() << "Connection: " << req.get("connection"); + snode::semantic::appLog().trace() << "Origin: " << req.get("origin"); + snode::semantic::appLog().trace() << "Sec-WebSocket-Protocol: " << req.get("sec-websocket-protocol"); + snode::semantic::appLog().trace() << "sec-web-socket-extensions: " << req.get("sec-websocket-extensions"); + snode::semantic::appLog().trace() << "sec-websocket-key: " << req.get("sec-websocket-key"); + snode::semantic::appLog().trace() << "sec-websocket-version: " << req.get("sec-websocket-version"); + snode::semantic::appLog().trace() << "upgrade: " << req.get("upgrade"); + snode::semantic::appLog().trace() << "user-agent: " << req.get("user-agent"); if (httputils::ci_contains(req.get("connection"), "Upgrade")) { res.upgrade(req); @@ -70,9 +71,9 @@ int main(int argc, char* argv[]) { legacyApp.listen([](const tls::in::WebApp::SocketAddress& socketAddress, int err) -> void { if (err != 0) { - PLOG(ERROR) << "OnError: " << err; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << err; } else { - VLOG(0) << "wsechoserver listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "wsechoserver listening on " << socketAddress.toString(); } }); @@ -84,10 +85,10 @@ int main(int argc, char* argv[]) { req.url = "/wstest.html"; } - VLOG(0) << 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](int ret) -> void { if (ret != 0) { - PLOG(ERROR) << req.url; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << req.url; } }); }); @@ -95,18 +96,18 @@ int main(int argc, char* argv[]) { tlsApp.get("/ws", [](Request& req, Response& res) -> void { std::string uri = req.originalUrl; - VLOG(1) << "OriginalUri: " << uri; - VLOG(1) << "Uri: " << req.url; + snode::semantic::appLog().trace() << "OriginalUri: " << uri; + snode::semantic::appLog().trace() << "Uri: " << req.url; - VLOG(1) << "Connection: " << req.get("connection"); - VLOG(1) << "Host: " << req.get("host"); - VLOG(1) << "Origin: " << req.get("origin"); - VLOG(1) << "Sec-WebSocket-Protocol: " << req.get("sec-websocket-protocol"); - VLOG(1) << "sec-web-socket-extensions: " << req.get("sec-websocket-extensions"); - VLOG(1) << "sec-websocket-key: " << req.get("sec-websocket-key"); - VLOG(1) << "sec-websocket-version: " << req.get("sec-websocket-version"); - VLOG(1) << "upgrade: " << req.get("upgrade"); - VLOG(1) << "user-agent: " << req.get("user-agent"); + snode::semantic::appLog().trace() << "Connection: " << req.get("connection"); + snode::semantic::appLog().trace() << "Host: " << req.get("host"); + snode::semantic::appLog().trace() << "Origin: " << req.get("origin"); + snode::semantic::appLog().trace() << "Sec-WebSocket-Protocol: " << req.get("sec-websocket-protocol"); + snode::semantic::appLog().trace() << "sec-web-socket-extensions: " << req.get("sec-websocket-extensions"); + snode::semantic::appLog().trace() << "sec-websocket-key: " << req.get("sec-websocket-key"); + snode::semantic::appLog().trace() << "sec-websocket-version: " << req.get("sec-websocket-version"); + snode::semantic::appLog().trace() << "upgrade: " << req.get("upgrade"); + snode::semantic::appLog().trace() << "user-agent: " << req.get("user-agent"); if (httputils::ci_contains(req.get("connection"), "Upgrade")) { res.upgrade(req); @@ -117,9 +118,9 @@ int main(int argc, char* argv[]) { tlsApp.listen([](const tls::in::WebApp::SocketAddress& socketAddress, int err) -> void { if (err != 0) { - PLOG(ERROR) << "OnError: " << err; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnError: " << err; } else { - VLOG(0) << "wsechoserver listening on " << socketAddress.toString(); + snode::semantic::appLog().trace() << "wsechoserver listening on " << socketAddress.toString(); } }); } diff --git a/src/apps/websocket/subprotocol/client/echo/Echo.cpp b/src/apps/websocket/subprotocol/client/echo/Echo.cpp index 0f70926808..d8573447ec 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) 2020, 2021, 2022, 2023 Volker Christian @@ -34,22 +35,22 @@ namespace apps::websocket::subprotocol::echo::client { } void Echo::onConnected() { - VLOG(0) << "Echo connected:"; + snode::semantic::appLog().trace() << "Echo connected:"; } void Echo::onMessageStart(int opCode) { - VLOG(0) << "Message Start - OpCode: " << opCode; + snode::semantic::appLog().trace() << "Message Start - OpCode: " << opCode; } void Echo::onMessageData(const char* junk, std::size_t junkLen) { data += std::string(junk, junkLen); - VLOG(0) << "Message Fragment: " << std::string(junk, junkLen); + snode::semantic::appLog().trace() << "Message Fragment: " << std::string(junk, junkLen); } void Echo::onMessageEnd() { - VLOG(0) << "Message Full Data: " << data; - VLOG(0) << "Message End"; + snode::semantic::appLog().trace() << "Message Full Data: " << data; + snode::semantic::appLog().trace() << "Message End"; /* forEachClient([&data = this->data](SubProtocol* client) { client->sendMessage(data); @@ -61,15 +62,15 @@ namespace apps::websocket::subprotocol::echo::client { } void Echo::onMessageError(uint16_t errnum) { - VLOG(0) << "Message error: " << errnum; + snode::semantic::appLog().trace() << "Message error: " << errnum; } void Echo::onDisconnected() { - VLOG(0) << "Echo disconnected:"; + snode::semantic::appLog().trace() << "Echo disconnected:"; } void Echo::onExit() { - VLOG(0) << "Echo exit:"; + snode::semantic::appLog().trace() << "Echo exit:"; sendClose(); } diff --git a/src/apps/websocket/subprotocol/server/echo/Echo.cpp b/src/apps/websocket/subprotocol/server/echo/Echo.cpp index aa9db604c9..ccba2b3773 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) 2020, 2021, 2022, 2023 Volker Christian @@ -34,25 +35,25 @@ namespace apps::websocket::subprotocol::echo::server { } void Echo::onConnected() { - VLOG(0) << "Echo connected:"; + snode::semantic::appLog().trace() << "Echo connected:"; sendMessage("Welcome to SimpleChat"); sendMessage("====================="); } void Echo::onMessageStart(int opCode) { - VLOG(0) << "Message Start - OpCode: " << opCode; + snode::semantic::appLog().trace() << "Message Start - OpCode: " << opCode; } void Echo::onMessageData(const char* junk, std::size_t junkLen) { data += std::string(junk, junkLen); - VLOG(0) << "Message Fragment: " << std::string(junk, junkLen); + snode::semantic::appLog().trace() << "Message Fragment: " << std::string(junk, junkLen); } void Echo::onMessageEnd() { - VLOG(0) << "Message Full Data: " << data; - VLOG(0) << "Message End"; + snode::semantic::appLog().trace() << "Message Full Data: " << data; + snode::semantic::appLog().trace() << "Message End"; /* forEachClient([&data = this->data](SubProtocol* client) { client->sendMessage(data); @@ -64,15 +65,15 @@ namespace apps::websocket::subprotocol::echo::server { } void Echo::onMessageError(uint16_t errnum) { - VLOG(0) << "Message error: " << errnum; + snode::semantic::appLog().trace() << "Message error: " << errnum; } void Echo::onDisconnected() { - VLOG(0) << "Echo disconnected:"; + snode::semantic::appLog().trace() << "Echo disconnected:"; } void Echo::onExit() { - VLOG(0) << "Echo exit:"; + snode::semantic::appLog().trace() << "Echo exit:"; sendClose(); } diff --git a/src/core/DescriptorEventReceiver.cpp b/src/core/DescriptorEventReceiver.cpp index c2219fbd43..5b6930263a 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) 2020, 2021, 2022, 2023 Volker Christian @@ -54,7 +55,7 @@ namespace core { enabled = true; descriptorEventPublisher.enable(this); } else { - LOG(WARNING) << "Double enable: " << getName() << ": fd = " << observedFd; + snode::semantic::appLog().warn() << "Double enable: " << getName() << ": fd = " << observedFd; } } @@ -73,7 +74,7 @@ namespace core { enabled = false; descriptorEventPublisher.disable(this); } else { - LOG(WARNING) << "Double disable: " << getName() << ": fd = " << observedFd; + snode::semantic::appLog().warn() << "Double disable: " << getName() << ": fd = " << observedFd; } } @@ -94,10 +95,10 @@ namespace core { descriptorEventPublisher.suspend(this); } } else { - LOG(WARNING) << "Double suspend: " << getName() << ": fd = " << observedFd; + snode::semantic::appLog().warn() << "Double suspend: " << getName() << ": fd = " << observedFd; } } else { - LOG(ERROR) << "Suspend while not enabled: " << getName() << ": fd = " << observedFd; + snode::semantic::appLog().error() << "Suspend while not enabled: " << getName() << ": fd = " << observedFd; } } @@ -111,10 +112,10 @@ namespace core { descriptorEventPublisher.resume(this); } } else { - LOG(WARNING) << "Double resume: " << getName() << ": fd = " << observedFd; + snode::semantic::appLog().warn() << "Double resume: " << getName() << ": fd = " << observedFd; } } else { - LOG(ERROR) << "Resume while not enabled: " << getName() << ": fd = " << observedFd; + snode::semantic::appLog().error() << "Resume while not enabled: " << getName() << ": fd = " << observedFd; } } diff --git a/src/core/DynamicLoader.cpp b/src/core/DynamicLoader.cpp index 27b5c3c507..703c71932b 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) 2020, 2021, 2022, 2023 Volker Christian @@ -38,9 +39,9 @@ namespace core { dlOpenedLibraries[handle].handle = handle; } dlOpenedLibraries[handle].refCount++; - LOG(TRACE) << "dlOpen file = " << libFile << ": success"; + snode::semantic::appLog().trace() << "dlOpen file = " << libFile << ": success"; } else { - LOG(WARNING) << "dlOpen " << DynamicLoader::dlError(); + snode::semantic::appLog().warn() << "dlOpen " << DynamicLoader::dlError(); } return handle; @@ -50,18 +51,18 @@ namespace core { if (handle != nullptr) { if (dlOpenedLibraries.contains(handle)) { if (std::find(closeHandles.begin(), closeHandles.end(), handle) == closeHandles.end()) { - LOG(TRACE) << "dlCloseDelayed file = " << dlOpenedLibraries[handle].fileName << ": registered"; + snode::semantic::appLog().trace() << "dlCloseDelayed file = " << dlOpenedLibraries[handle].fileName << ": registered"; closeHandles.push_back(handle); } else { - LOG(ERROR) << "dlCloseDelayed file = " << dlOpenedLibraries[handle].fileName + snode::semantic::appLog().error() << "dlCloseDelayed file = " << dlOpenedLibraries[handle].fileName << ": already registered for dlCloseDelayed"; } } else { - LOG(WARNING) << "dlCloseDelayed handle = " << handle << ": not opened using dlOpen"; + snode::semantic::appLog().warn() << "dlCloseDelayed handle = " << handle << ": not opened using dlOpen"; } } else { - LOG(ERROR) << "dlCloseDelayed handle: nullptr"; + snode::semantic::appLog().error() << "dlCloseDelayed handle: nullptr"; } } @@ -75,13 +76,13 @@ namespace core { dlOpenedLibraries.erase(handle); } else { - LOG(WARNING) << "dlClose handle = " << handle << ": not opened with dlOpen"; + snode::semantic::appLog().warn() << "dlClose handle = " << handle << ": not opened with dlOpen"; } } else { - LOG(ERROR) << "dlClose handle = " << handle << ": already registered for dlCloseDelayed"; + snode::semantic::appLog().error() << "dlClose handle = " << handle << ": already registered for dlCloseDelayed"; } } else { - LOG(ERROR) << "dlClose handle: nullptr"; + snode::semantic::appLog().error() << "dlClose handle: nullptr"; } return ret; @@ -94,9 +95,9 @@ namespace core { ret = execDlClose(library); if (ret != 0) { - LOG(WARNING) << "dlClose: " << DynamicLoader::dlError(); + snode::semantic::appLog().warn() << "dlClose: " << DynamicLoader::dlError(); } else { - LOG(TRACE) << "dlClose file = " << library.fileName << ": closed"; + snode::semantic::appLog().trace() << "dlClose file = " << library.fileName << ": closed"; } } @@ -124,9 +125,9 @@ namespace core { Library& library = dlOpenedLibraries[handle]; if (execDlClose(library) != 0) { - LOG(WARNING) << "execDlCloseDeleyed file = " << library.fileName << ": " << DynamicLoader::dlError(); + snode::semantic::appLog().warn() << "execDlCloseDeleyed file = " << library.fileName << ": " << DynamicLoader::dlError(); } else { - LOG(TRACE) << "execDlCloseDeleyed file = " << library.fileName << ": closed"; + snode::semantic::appLog().trace() << "execDlCloseDeleyed file = " << library.fileName << ": closed"; } dlOpenedLibraries.erase(handle); @@ -142,9 +143,9 @@ namespace core { int ret = dlClose(library); if (ret != 0) { - LOG(WARNING) << "execDlCloseAll file = " << library.fileName << ": " << DynamicLoader::dlError(); + snode::semantic::appLog().warn() << "execDlCloseAll file = " << library.fileName << ": " << DynamicLoader::dlError(); } else { - LOG(TRACE) << "execDlCloseAll file = " << library.fileName << ": closed"; + snode::semantic::appLog().trace() << "execDlCloseAll file = " << library.fileName << ": closed"; } } diff --git a/src/core/EventLoop.cpp b/src/core/EventLoop.cpp index 53231e52b2..537ed10f74 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) 2020, 2021, 2022, 2023 Volker Christian @@ -94,7 +95,7 @@ namespace core { TickStatus EventLoop::tick(const utils::Timeval& timeOut) { if (!(eventLoopState == State::INITIALIZED)) { - PLOG(ERROR) << "snode.c not initialized. Use SNodeC::init(argc, argv) before SNodeC::tick()."; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "snode.c not initialized. Use SNodeC::init(argc, argv) before SNodeC::tick()."; exit(1); } @@ -142,13 +143,13 @@ namespace core { switch (tickStatus) { case TickStatus::SUCCESS: - LOG(INFO) << "EventLoop terminated: Releasing resources"; + snode::semantic::appLog().info() << "EventLoop terminated: Releasing resources"; break; case TickStatus::NO_OBSERVER: - LOG(INFO) << "EventLoop: No Observer - exiting"; + snode::semantic::appLog().info() << "EventLoop: No Observer - exiting"; break; case TickStatus::ERROR: - PLOG(ERROR) << "EventPublisher::span()"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "EventPublisher::span()"; break; } @@ -201,7 +202,7 @@ namespace core { utils::Config::terminate(); - LOG(INFO) << "All resources released"; + snode::semantic::appLog().info() << "All resources released"; } State EventLoop::state() { @@ -209,7 +210,7 @@ namespace core { } void EventLoop::stoponsig(int sig) { - LOG(INFO) << "Received signal " << sig; + snode::semantic::appLog().info() << "Received signal " << sig; stopsig = sig; stop(); } diff --git a/src/core/TimerEventReceiver.cpp b/src/core/TimerEventReceiver.cpp index 48fc2eb42a..57b2243d70 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) 2020, 2021, 2022, 2023 Volker Christian @@ -77,7 +78,7 @@ namespace core { } void TimerEventReceiver::onEvent(const utils::Timeval& currentTime) { - LOG(TRACE) << "Timer: Dispatch delta = " << (currentTime - getTimeoutAbsolut()).msd() << " ms"; + snode::semantic::appLog().trace() << "Timer: Dispatch delta = " << (currentTime - getTimeoutAbsolut()).msd() << " ms"; dispatchEvent(); } diff --git a/src/core/multiplexer/epoll/EventMultiplexer.cpp b/src/core/multiplexer/epoll/EventMultiplexer.cpp index 625b8976ef..62d41d3a25 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) 2020, 2021, 2022, 2023 Volker Christian @@ -54,7 +55,7 @@ namespace core::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(TRACE) << "IO-Multiplexer: epoll"; + snode::semantic::appLog().trace() << "IO-Multiplexer: epoll"; } int EventMultiplexer::monitorDescriptors(utils::Timeval& tickTimeout) { diff --git a/src/core/multiplexer/poll/EventMultiplexer.cpp b/src/core/multiplexer/poll/EventMultiplexer.cpp index 9ccbfca3b8..2051fa7531 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) 2020, 2021, 2022, 2023 Volker Christian @@ -131,7 +132,7 @@ namespace core::poll { new core::poll::DescriptorEventPublisher("READ", pollFdsManager, POLLIN, POLLIN | POLLHUP | POLLRDHUP | POLLERR), new core::poll::DescriptorEventPublisher("WRITE", pollFdsManager, POLLOUT, POLLOUT), new core::poll::DescriptorEventPublisher("EXCEPT", pollFdsManager, POLLPRI, POLLPRI)) { - LOG(TRACE) << "IO-Multiplexer: poll"; + snode::semantic::appLog().trace() << "IO-Multiplexer: poll"; } int EventMultiplexer::monitorDescriptors(utils::Timeval& tickTimeOut) { diff --git a/src/core/multiplexer/select/EventMultiplexer.cpp b/src/core/multiplexer/select/EventMultiplexer.cpp index e223736a18..3de6a34225 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) 2020, 2021, 2022, 2023 Volker Christian @@ -38,7 +39,7 @@ namespace core::select { : core::EventMultiplexer(new core::select::DescriptorEventPublisher("READ", fdSets[core::EventMultiplexer::DISP_TYPE::RD]), new core::select::DescriptorEventPublisher("WRITE", fdSets[core::EventMultiplexer::DISP_TYPE::WR]), new core::select::DescriptorEventPublisher("EXCEPT", fdSets[core::EventMultiplexer::DISP_TYPE::EX])) { - LOG(TRACE) << "IO-Multiplexer: select"; + snode::semantic::appLog().trace() << "IO-Multiplexer: select"; } int EventMultiplexer::monitorDescriptors(utils::Timeval& tickTimeOut) { diff --git a/src/core/socket/SocketContext.cpp b/src/core/socket/SocketContext.cpp index d064920ea1..6f95f37f36 100644 --- a/src/core/socket/SocketContext.cpp +++ b/src/core/socket/SocketContext.cpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -32,18 +33,18 @@ namespace core::socket { void SocketContext::onWriteError(int errnum) { if (errnum != 0) { - PLOG(ERROR) << "OnWriteError: " << errnum; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnWriteError: " << errnum; } } void SocketContext::onReadError(int errnum) { if (errnum != 0) { - PLOG(ERROR) << "OnReadError: " << errnum; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "OnReadError: " << errnum; } } void SocketContext::onExit() { - LOG(INFO) << "Protocol exit"; + snode::semantic::appLog().info() << "Protocol exit"; } } // namespace core::socket diff --git a/src/core/socket/stream/SocketAcceptor.hpp b/src/core/socket/stream/SocketAcceptor.hpp index d2c313dd34..c94a3306ec 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) 2020, 2021, 2022, 2023 Volker Christian @@ -82,7 +83,7 @@ namespace core::socket::stream { if (physicalClientSocket.isValid()) { socketConnectionFactory.create(physicalClientSocket, config); } else if (errno != EINTR && errno != EAGAIN && errno != EWOULDBLOCK) { - PLOG(ERROR) << "accept"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "accept"; } } while (--acceptsPerTick > 0); } diff --git a/src/core/socket/stream/SocketClient.h b/src/core/socket/stream/SocketClient.h index fa30138fc8..3004be4c2e 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) 2020, 2021, 2022, 2023 Volker Christian @@ -69,22 +70,22 @@ namespace core::socket::stream { : SocketClient( name, [name](SocketConnection* socketConnection) -> void { // onConnect - VLOG(0) << "OnConnect " << name; + snode::semantic::appLog().trace() << "OnConnect " << name; - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }, [name]([[maybe_unused]] SocketConnection* socketConnection) -> void { // onConnected - VLOG(0) << "OnConnected " << name; + snode::semantic::appLog().trace() << "OnConnected " << name; }, [name](SocketConnection* socketConnection) -> void { // onDisconnect - VLOG(0) << "OnDisconnect " << name; + snode::semantic::appLog().trace() << "OnDisconnect " << name; - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }) { } @@ -117,22 +118,22 @@ namespace core::socket::stream { name, socketContextFactory, [name](SocketConnection* socketConnection) -> void { // onConnect - VLOG(0) << "OnConnect " << name; + snode::semantic::appLog().trace() << "OnConnect " << name; - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }, [name]([[maybe_unused]] SocketConnection* socketConnection) -> void { // onConnected - VLOG(0) << "OnConnected " << name; + snode::semantic::appLog().trace() << "OnConnected " << name; }, [name](SocketConnection* socketConnection) -> void { // onDisconnect - VLOG(0) << "OnDisconnect " << name; + snode::semantic::appLog().trace() << "OnDisconnect " << name; - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }) { } diff --git a/src/core/socket/stream/SocketConnection.cpp b/src/core/socket/stream/SocketConnection.cpp index d8332b0d8b..9da0d6fcbf 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) 2020, 2021, 2022, 2023 Volker Christian @@ -36,7 +37,7 @@ namespace core::socket::stream { newSocketContext = socketContextFactory->create(this); if (newSocketContext == nullptr) { - VLOG(0) << "Switch socket context unsuccessull: new socket context not created"; + snode::semantic::appLog().trace() << "Switch socket context unsuccessull: new socket context not created"; } return newSocketContext; @@ -47,7 +48,7 @@ namespace core::socket::stream { socketContext = socketContextFactory->create(this); if (socketContext == nullptr) { - VLOG(0) << "Set socket context unsuccessull: new socket context not created"; + snode::semantic::appLog().trace() << "Set socket context unsuccessull: new socket context not created"; } return socketContext; diff --git a/src/core/socket/stream/SocketConnection.hpp b/src/core/socket/stream/SocketConnection.hpp index 202b39328f..507d98f88f 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) 2020, 2021, 2022, 2023 Volker Christian @@ -122,7 +123,7 @@ namespace core::socket::stream { void SocketConnectionT::shutdownWrite(bool forceClose) { SocketWriter::shutdown([forceClose, this](int errnum) -> void { if (errnum != 0) { - PLOG(INFO) << "SocketWriter::doWriteShutdown"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Info, errno) << "SocketWriter::doWriteShutdown"; } if (forceClose) { close(); @@ -173,7 +174,7 @@ namespace core::socket::stream { if (newSocketContext == nullptr) { ret = SocketReader::readFromPeer(junk, junkLen); } else { - VLOG(0) << "ReadFromPeer: OldSocketContext != nullptr: SocketContextSwitch in progress"; + snode::semantic::appLog().trace() << "ReadFromPeer: OldSocketContext != nullptr: SocketContextSwitch in progress"; } return ret; @@ -188,7 +189,7 @@ namespace core::socket::stream { if (newSocketContext == nullptr) { SocketWriter::sendToPeer(junk, junkLen); } else { - VLOG(0) << "SendToPeer: OldSocketContext != nullptr: SocketContextSwitch in progress"; + snode::semantic::appLog().trace() << "SendToPeer: OldSocketContext != nullptr: SocketContextSwitch in progress"; } } diff --git a/src/core/socket/stream/SocketConnectionFactory.hpp b/src/core/socket/stream/SocketConnectionFactory.hpp index 7266e9c4c7..4cfe1e359e 100644 --- a/src/core/socket/stream/SocketConnectionFactory.hpp +++ b/src/core/socket/stream/SocketConnectionFactory.hpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -67,7 +68,7 @@ namespace core::socket::stream { socketConnection = nullptr; } } else { - PLOG(ERROR) << "getsockname"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << "getsockname"; } } diff --git a/src/core/socket/stream/SocketServer.h b/src/core/socket/stream/SocketServer.h index e6da7ec261..f0b3dec5b6 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) 2020, 2021, 2022, 2023 Volker Christian @@ -64,22 +65,22 @@ namespace core::socket::stream { : SocketServer( name, [name](SocketConnection* socketConnection) -> void { // onConnect - VLOG(0) << "OnConnect - " << name; + snode::semantic::appLog().trace() << "OnConnect - " << name; - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }, [name]([[maybe_unused]] SocketConnection* socketConnection) -> void { // onConnected - VLOG(0) << "OnConnected - " << name; + snode::semantic::appLog().trace() << "OnConnected - " << name; }, [name](SocketConnection* socketConnection) -> void { // onDisconnect - VLOG(0) << "OnDisconnect " << name; + snode::semantic::appLog().trace() << "OnDisconnect " << name; - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }) { } @@ -112,22 +113,22 @@ namespace core::socket::stream { name, socketContextFactory, [name](SocketConnection* socketConnection) -> void { // onConnect - VLOG(0) << "OnConnect " << name; + snode::semantic::appLog().trace() << "OnConnect " << name; - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }, [name]([[maybe_unused]] SocketConnection* socketConnection) -> void { // onConnected - VLOG(0) << "OnConnected " << name; + snode::semantic::appLog().trace() << "OnConnected " << name; }, [name](SocketConnection* socketConnection) -> void { // onDisconnect - VLOG(0) << "OnDisconnect " << name; + snode::semantic::appLog().trace() << "OnDisconnect " << name; - VLOG(0) << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tLocal: (" + socketConnection->getLocalAddress().address() + ") " + socketConnection->getLocalAddress().toString(); - VLOG(0) << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + + snode::semantic::appLog().trace() << "\tPeer: (" + socketConnection->getRemoteAddress().address() + ") " + socketConnection->getRemoteAddress().toString(); }) { } diff --git a/src/core/socket/stream/SocketWriter.hpp b/src/core/socket/stream/SocketWriter.hpp index 080b711c65..4b9c72524a 100644 --- a/src/core/socket/stream/SocketWriter.hpp +++ b/src/core/socket/stream/SocketWriter.hpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -100,7 +101,7 @@ namespace core::socket::stream { void SocketWriter::doWriteShutdown(const std::function& onShutdown) { errno = 0; - LOG(TRACE) << "Do syscall shutdonw(WR)"; + snode::semantic::appLog().trace() << "Do syscall shutdonw(WR)"; PhysicalSocket::shutdown(PhysicalSocket::SHUT::WR); @@ -113,7 +114,7 @@ namespace core::socket::stream { this->onShutdown = onShutdown; if (writeBuffer.empty()) { shutdownInProgress = true; - LOG(TRACE) << "Initiating shutdown process"; + snode::semantic::appLog().trace() << "Initiating shutdown process"; doWriteShutdown(onShutdown); } else { markShutdown = true; @@ -127,7 +128,7 @@ namespace core::socket::stream { setTimeout(terminateTimeout); shutdown([this]([[maybe_unused]] int errnum) -> void { if (errnum != 0) { - PLOG(INFO) << "SocketWriter::doWriteShutdown"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Info, errno) << "SocketWriter::doWriteShutdown"; } disable(); }); diff --git a/src/core/socket/stream/tls/SocketAcceptor.hpp b/src/core/socket/stream/tls/SocketAcceptor.hpp index 792e4d9152..f2d09692c6 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) 2020, 2021, 2022, 2023 Volker Christian @@ -57,12 +58,12 @@ namespace core::socket::stream::tls { socketConnection->doSSLHandshake( [&onConnected, socketConnection]() -> void { // onSuccess - LOG(INFO) << "SSL/TLS initial handshake success"; + snode::semantic::appLog().info() << "SSL/TLS initial handshake success"; onConnected(socketConnection); socketConnection->onConnected(); }, []() -> void { // onTimeout - LOG(WARNING) << "SSL/TLS initial handshake timed out"; + snode::semantic::appLog().warn() << "SSL/TLS initial handshake timed out"; }, [](int sslErr) -> void { // onError ssl_log("SSL/TLS initial handshake failed", sslErr); @@ -108,7 +109,7 @@ namespace core::socket::stream::tls { masterSslCtxSans = ssl_get_sans(masterSslCtx); for (const std::string& san : masterSslCtxSans) { - LOG(INFO) << "SSL_CTX for (san)'" << san << "' as master installed"; + snode::semantic::appLog().info() << "SSL_CTX for (san)'" << san << "' as master installed"; } for (const auto& [domain, sniCertConf] : config->getSniCerts()) { @@ -122,16 +123,16 @@ namespace core::socket::stream::tls { } sniSslCtxs.insert_or_assign(domain, sniSslCtx); - LOG(INFO) << "SSL_CTX for (dom)'" << domain << "' as server name indication (sni) installed"; + snode::semantic::appLog().info() << "SSL_CTX for (dom)'" << domain << "' as server name indication (sni) installed"; } for (const std::string& san : ssl_get_sans(sniSslCtx)) { sniSslCtxs.insert({san, sniSslCtx}); - LOG(INFO) << "SSL_CTX for (san)'" << san << "' as server name indication (sni) installed"; + snode::semantic::appLog().info() << "SSL_CTX for (san)'" << san << "' as server name indication (sni) installed"; } } else { - LOG(INFO) << "Can not create SNI_SSL_CTX for domain '" << domain << "'"; + snode::semantic::appLog().info() << "Can not create SNI_SSL_CTX for domain '" << domain << "'"; } } } @@ -153,18 +154,18 @@ namespace core::socket::stream::tls { SSL_CTX* SocketAcceptor::getMasterSniCtx(const std::string& serverNameIndication) { SSL_CTX* sniSslCtx = nullptr; - LOG(INFO) << "Search for sni = '" << serverNameIndication << "' in master certificate"; + snode::semantic::appLog().info() << "Search for sni = '" << serverNameIndication << "' in master certificate"; std::set::iterator masterSniIt = std::find_if(masterSslCtxSans.begin(), masterSslCtxSans.end(), [&serverNameIndication](const std::string& sni) -> bool { - LOG(TRACE) << " .. " << sni.c_str(); + snode::semantic::appLog().trace() << " .. " << sni.c_str(); return match(sni.c_str(), serverNameIndication.c_str()); }); if (masterSniIt != masterSslCtxSans.end()) { - LOG(INFO) << "found: " << *masterSniIt; + snode::semantic::appLog().info() << "found: " << *masterSniIt; sniSslCtx = masterSslCtx; } else { - LOG(INFO) << "not found"; + snode::semantic::appLog().info() << "not found"; } return sniSslCtx; @@ -174,19 +175,19 @@ namespace core::socket::stream::tls { SSL_CTX* SocketAcceptor::getPoolSniCtx(const std::string& serverNameIndication) { SSL_CTX* sniCtx = nullptr; - LOG(INFO) << "Search for sni = '" << serverNameIndication << "' in sni certificates"; + snode::semantic::appLog().info() << "Search for sni = '" << serverNameIndication << "' in sni certificates"; std::map::iterator sniPairIt = std::find_if( sniSslCtxs.begin(), sniSslCtxs.end(), [&serverNameIndication](const std::pair& sniPair) -> bool { - LOG(TRACE) << " .. " << sniPair.first.c_str(); + snode::semantic::appLog().trace() << " .. " << sniPair.first.c_str(); return match(sniPair.first.c_str(), serverNameIndication.c_str()); }); if (sniPairIt != sniSslCtxs.end()) { - LOG(INFO) << "found: " << sniPairIt->first; + snode::semantic::appLog().info() << "found: " << sniPairIt->first; sniCtx = sniPairIt->second; } else { - LOG(INFO) << "not found"; + snode::semantic::appLog().info() << "not found"; } return sniCtx; @@ -214,17 +215,17 @@ namespace core::socket::stream::tls { if (!serverNameIndication.empty()) { SSL_CTX* sniSslCtx = socketAcceptor->getSniCtx(serverNameIndication); if (sniSslCtx != nullptr) { - LOG(INFO) << "Setting sni certificate for " << serverNameIndication; + snode::semantic::appLog().info() << "Setting sni certificate for " << serverNameIndication; ssl_set_ssl_ctx(ssl, sniSslCtx); } else if (socketAcceptor->forceSni) { - LOG(WARNING) << "No sni certificate found but forceSni set - terminating"; + snode::semantic::appLog().warn() << "No sni certificate found but forceSni set - terminating"; ret = SSL_CLIENT_HELLO_ERROR; *al = SSL_AD_UNRECOGNIZED_NAME; } else { - LOG(INFO) << "No sni certificate found - still using master certificate"; + snode::semantic::appLog().info() << "No sni certificate found - still using master certificate"; } } else { - LOG(INFO) << "No sni certificate set - the client did not request one"; + snode::semantic::appLog().info() << "No sni certificate set - the client did not request one"; } return ret; diff --git a/src/core/socket/stream/tls/SocketConnection.hpp b/src/core/socket/stream/tls/SocketConnection.hpp index b001be2272..20c52b362b 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) 2020, 2021, 2022, 2023 Volker Christian @@ -180,17 +181,17 @@ namespace core::socket::stream::tls { template void core::socket::stream::tls::SocketConnection::doSSLShutdown() { if (SSL_get_shutdown(ssl) == (SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN)) { - VLOG(0) << "SSL_Shutdown COMPLETED: Close_notify sent and received"; + snode::semantic::appLog().trace() << "SSL_Shutdown COMPLETED: Close_notify sent and received"; if (SocketWriter::isEnabled()) { SocketWriter::doWriteShutdown([this]([[maybe_unused]] int errnum) -> void { if (errno != 0) { - PLOG(INFO) << "SocketWriter::doWriteShutdown"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Info, errno) << "SocketWriter::doWriteShutdown"; } SocketWriter::disable(); }); } } else { - VLOG(0) << "SSL_Shutdown WAITING: Close_notify received but not send"; + snode::semantic::appLog().trace() << "SSL_Shutdown WAITING: Close_notify received but not send"; } } @@ -200,17 +201,17 @@ namespace core::socket::stream::tls { doSSLShutdown( [this, &onShutdown]() -> void { // thus send one if (SSL_get_shutdown(ssl) == (SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN)) { - VLOG(0) << "SSL_Shutdown COMPLETED: Close_notify sent and received"; + snode::semantic::appLog().trace() << "SSL_Shutdown COMPLETED: Close_notify sent and received"; SocketWriter::doWriteShutdown(onShutdown); } else { - VLOG(0) << "SSL_Shutdown WAITING: Close_notify sent but not received"; + snode::semantic::appLog().trace() << "SSL_Shutdown WAITING: Close_notify sent but not received"; } }, [this]() -> void { - LOG(WARNING) << "SSL_shutdown: Handshake timed out"; + snode::semantic::appLog().warn() << "SSL_shutdown: Handshake timed out"; SocketWriter::doWriteShutdown([this]([[maybe_unused]] int errnum) -> void { if (errno != 0) { - PLOG(INFO) << "SocketWriter::doWriteShutdown"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Info, errno) << "SocketWriter::doWriteShutdown"; } SocketConnection::close(); }); @@ -219,7 +220,7 @@ namespace core::socket::stream::tls { ssl_log("SSL_shutdown: Handshake failed", sslErr); SocketWriter::doWriteShutdown([this]([[maybe_unused]] int errnum) -> void { if (errno != 0) { - PLOG(INFO) << "SocketWriter::doWriteShutdown"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Info, errno) << "SocketWriter::doWriteShutdown"; } SocketConnection::close(); }); diff --git a/src/core/socket/stream/tls/SocketConnector.hpp b/src/core/socket/stream/tls/SocketConnector.hpp index 70c31a10c5..a5dadbeb68 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) 2020, 2021, 2022, 2023 Volker Christian @@ -56,12 +57,12 @@ namespace core::socket::stream::tls { socketConnection->doSSLHandshake( [onConnected, socketConnection]() -> void { // onSuccess - LOG(INFO) << "SSL/TLS initial handshake success"; + snode::semantic::appLog().info() << "SSL/TLS initial handshake success"; onConnected(socketConnection); socketConnection->onConnected(); }, [onError = this->onError, config = this->config]() -> void { // onTimeout - LOG(WARNING) << "SSL/TLS initial handshake timed out"; + snode::semantic::appLog().warn() << "SSL/TLS initial handshake timed out"; onError(config->Remote::getAddress(), ETIMEDOUT); }, [onError = this->onError, config = this->config](int sslErr) -> void { // onError diff --git a/src/core/socket/stream/tls/SocketReader.hpp b/src/core/socket/stream/tls/SocketReader.hpp index 37caa75d60..d7de1439db 100644 --- a/src/core/socket/stream/tls/SocketReader.hpp +++ b/src/core/socket/stream/tls/SocketReader.hpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -50,13 +51,13 @@ namespace core::socket::stream::tls { case SSL_ERROR_WANT_WRITE: { utils::PreserveErrno preserveErrno; - LOG(INFO) << "SSL/TLS start renegotiation on read"; + snode::semantic::appLog().info() << "SSL/TLS start renegotiation on read"; doSSLHandshake( []() -> void { - LOG(INFO) << "SSL/TLS renegotiation on read success"; + snode::semantic::appLog().info() << "SSL/TLS renegotiation on read success"; }, []() -> void { - LOG(WARNING) << "SSL/TLS renegotiation on read timed out"; + snode::semantic::appLog().warn() << "SSL/TLS renegotiation on read timed out"; }, [](int ssl_err) -> void { ssl_log("SSL/TLS renegotiation", ssl_err); @@ -74,7 +75,7 @@ namespace core::socket::stream::tls { utils::PreserveErrno preserveErrno; SSL_set_shutdown(ssl, SSL_get_shutdown(ssl) | SSL_RECEIVED_SHUTDOWN); - VLOG(0) << "SSL/TLS: TCP-FIN without close_notify. Emulating SSL_RECEIVED_SHUTDOWN"; + snode::semantic::appLog().trace() << "SSL/TLS: TCP-FIN without close_notify. Emulating SSL_RECEIVED_SHUTDOWN"; doSSLShutdown(); } ret = -1; diff --git a/src/core/socket/stream/tls/SocketWriter.hpp b/src/core/socket/stream/tls/SocketWriter.hpp index 6d0f728d19..999e89255b 100644 --- a/src/core/socket/stream/tls/SocketWriter.hpp +++ b/src/core/socket/stream/tls/SocketWriter.hpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -45,13 +46,13 @@ namespace core::socket::stream::tls { case SSL_ERROR_WANT_READ: { utils::PreserveErrno preserveErrno; - LOG(INFO) << "SSL/TLS start renegotiation on write"; + snode::semantic::appLog().info() << "SSL/TLS start renegotiation on write"; doSSLHandshake( []() -> void { - LOG(INFO) << "SSL/TLS renegotiation on write success"; + snode::semantic::appLog().info() << "SSL/TLS renegotiation on write success"; }, []() -> void { - LOG(WARNING) << "SSL/TLS renegotiation on write timed out"; + snode::semantic::appLog().warn() << "SSL/TLS renegotiation on write timed out"; }, [](int ssl_err) -> void { ssl_log("SSL/TLS renegotiation", ssl_err); diff --git a/src/core/socket/stream/tls/ssl_utils.cpp b/src/core/socket/stream/tls/ssl_utils.cpp index 5c3acabc76..363a4a19fb 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) 2020, 2021, 2022, 2023 Volker Christian @@ -71,9 +72,9 @@ namespace core::socket::stream::tls { X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256); if (!preverify_ok) { - LOG(INFO) << "verify_error:num=" << err << ": " << X509_verify_cert_error_string(err) << ":depth=" << depth << ": " << buf; + snode::semantic::appLog().info() << "verify_error:num=" << err << ": " << X509_verify_cert_error_string(err) << ":depth=" << depth << ": " << buf; } else { - LOG(TRACE) << "depth=" << depth << ": " << buf; + snode::semantic::appLog().trace() << "depth=" << depth << ": " << buf; } /* @@ -83,7 +84,7 @@ namespace core::socket::stream::tls { if (!preverify_ok && (err == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT)) { X509_NAME_oneline(X509_get_issuer_name(err_cert), buf, 256); - LOG(WARNING) << "no issuer certificate for issuer= " << buf; + snode::semantic::appLog().warn() << "no issuer certificate for issuer= " << buf; } return preverify_ok; @@ -365,29 +366,29 @@ namespace core::socket::stream::tls { } void ssl_log_error(const std::string& message) { - PLOG(ERROR) << message; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << message; unsigned long errorCode = 0; while ((errorCode = ERR_get_error()) != 0) { - LOG(ERROR) << "|-- with SSL " << ERR_error_string(errorCode, nullptr); + snode::semantic::appLog().error() << "|-- with SSL " << ERR_error_string(errorCode, nullptr); } } void ssl_log_warning(const std::string& message) { - LOG(WARNING) << message; + snode::semantic::appLog().warn() << message; unsigned long errorCode = 0; while ((errorCode = ERR_get_error()) != 0) { - LOG(WARNING) << "|-- with SSL " << ERR_error_string(errorCode, nullptr); + snode::semantic::appLog().warn() << "|-- with SSL " << ERR_error_string(errorCode, nullptr); } } void ssl_log_info(const std::string& message) { - PLOG(INFO) << message; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Info, errno) << message; unsigned long errorCode = 0; while ((errorCode = ERR_get_error()) != 0) { - LOG(INFO) << "|-- with SSL " << ERR_error_string(errorCode, nullptr); + snode::semantic::appLog().info() << "|-- with SSL " << ERR_error_string(errorCode, nullptr); } } diff --git a/src/database/mariadb/MariaDBConnection.cpp b/src/database/mariadb/MariaDBConnection.cpp index 0a22979a13..b0cb50550a 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) 2020, 2021, 2022, 2023 Volker Christian @@ -52,7 +53,7 @@ namespace database::mariadb { if (mysql_errno(mysql) == 0) { int fd = mysql_get_socket(mysql); - VLOG(0) << "Got valid descriptor: " << fd; + snode::semantic::appLog().trace() << "Got valid descriptor: " << fd; ReadEventReceiver::enable(fd); WriteEventReceiver::enable(fd); @@ -64,14 +65,14 @@ namespace database::mariadb { connected = true; } else { - VLOG(0) << "Got no valid descriptor: " << mysql_error(mysql) << ", " << mysql_errno(mysql); + snode::semantic::appLog().trace() << "Got no valid descriptor: " << mysql_error(mysql) << ", " << mysql_errno(mysql); } }, []() -> void { - VLOG(0) << "Connect success"; + snode::semantic::appLog().trace() << "Connect success"; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - VLOG(0) << "Connect error: " << errorString << " : " << errorNumber; + snode::semantic::appLog().trace() << "Connect error: " << errorString << " : " << errorNumber; })))); } @@ -145,7 +146,7 @@ namespace database::mariadb { } void MariaDBConnection::commandCompleted() { - VLOG(0) << "Completed: " << currentCommand->commandInfo(); + snode::semantic::appLog().trace() << "Completed: " << currentCommand->commandInfo(); commandSequenceQueue.front().commandCompleted(); if (commandSequenceQueue.front().empty()) { diff --git a/src/express/middleware/StaticMiddleware.cpp b/src/express/middleware/StaticMiddleware.cpp index b0c276261c..07494d0b9c 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) 2020, 2021, 2022, 2023 Volker Christian @@ -45,24 +46,24 @@ namespace express::middleware { } next(); } else { - LOG(DEBUG) << "Wrong method " << req.method; + snode::semantic::appLog().debug() << "Wrong method " << req.method; res.set("Connection", "Close"); res.sendStatus(400); } }, [] MIDDLEWARE(req, res, next) { if (req.url == "/") { - LOG(INFO) << "REDIRECT " + req.url + " -> " + "/index.html"; + snode::semantic::appLog().info() << "REDIRECT " + req.url + " -> " + "/index.html"; res.redirect(308, "/index.html"); } else { next(); } }, [&root = this->root] APPLICATION(req, res) { - LOG(INFO) << "GET " + req.url + " -> " + root + req.url; + snode::semantic::appLog().info() << "GET " + req.url + " -> " + root + req.url; res.sendFile(root + req.url, [&req, &res](int ret) -> void { if (ret != 0) { - PLOG(ERROR) << req.url; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errno) << req.url; res.status(404).end(); } }); diff --git a/src/iot/mqtt-fast/SocketContext.cpp b/src/iot/mqtt-fast/SocketContext.cpp index a11a3f5a30..c8f5dbced5 100644 --- a/src/iot/mqtt-fast/SocketContext.cpp +++ b/src/iot/mqtt-fast/SocketContext.cpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022 Volker Christian @@ -39,99 +40,99 @@ namespace iot::mqtt_fast { } void SocketContext::sendConnect(const std::string& clientId) { - LOG(TRACE) << "Send CONNECT"; - LOG(TRACE) << "============"; + snode::semantic::appLog().trace() << "Send CONNECT"; + snode::semantic::appLog().trace() << "============"; send(iot::mqtt_fast::packets::Connect(clientId)); } void SocketContext::sendConnack(uint8_t returnCode, uint8_t flags) { - LOG(TRACE) << "Send CONNACK"; - LOG(TRACE) << "============"; + snode::semantic::appLog().trace() << "Send CONNACK"; + snode::semantic::appLog().trace() << "============"; send(iot::mqtt_fast::packets::Connack(returnCode, flags)); } void SocketContext::sendPublish(const std::string& topic, const std::string& message, bool dup, uint8_t qoS, bool retain) { - LOG(TRACE) << "Send PUBLISH"; - LOG(TRACE) << "============"; + snode::semantic::appLog().trace() << "Send PUBLISH"; + snode::semantic::appLog().trace() << "============"; send(iot::mqtt_fast::packets::Publish(qoS == 0 ? 0 : getPacketIdentifier(), topic, message, dup, qoS, retain)); } void SocketContext::sendPuback(uint16_t packetIdentifier) { - LOG(TRACE) << "Send PUBACK"; - LOG(TRACE) << "==========="; + snode::semantic::appLog().trace() << "Send PUBACK"; + snode::semantic::appLog().trace() << "==========="; send(iot::mqtt_fast::packets::Puback(packetIdentifier)); } void SocketContext::sendPubrec(uint16_t packetIdentifier) { - LOG(TRACE) << "Send PUBREC"; - LOG(TRACE) << "==========="; + snode::semantic::appLog().trace() << "Send PUBREC"; + snode::semantic::appLog().trace() << "==========="; send(iot::mqtt_fast::packets::Pubrec(packetIdentifier)); } void SocketContext::sendPubrel(uint16_t packetIdentifier) { - LOG(TRACE) << "Send PUBREL"; - LOG(TRACE) << "==========="; + snode::semantic::appLog().trace() << "Send PUBREL"; + snode::semantic::appLog().trace() << "==========="; send(iot::mqtt_fast::packets::Pubrel(packetIdentifier)); } void SocketContext::sendPubcomp(uint16_t packetIdentifier) { - LOG(TRACE) << "Send PUBCOMP"; - LOG(TRACE) << "============"; + snode::semantic::appLog().trace() << "Send PUBCOMP"; + snode::semantic::appLog().trace() << "============"; send(iot::mqtt_fast::packets::Pubcomp(packetIdentifier)); } void SocketContext::sendSubscribe(std::list& topics) { - LOG(TRACE) << "Send SUBSCRIBE"; - LOG(TRACE) << "=============="; + snode::semantic::appLog().trace() << "Send SUBSCRIBE"; + snode::semantic::appLog().trace() << "=============="; send(iot::mqtt_fast::packets::Subscribe(getPacketIdentifier(), topics)); } void SocketContext::sendSuback(uint16_t packetIdentifier, std::list& returnCodes) { - LOG(TRACE) << "Send SUBACK"; - LOG(TRACE) << "==========="; + snode::semantic::appLog().trace() << "Send SUBACK"; + snode::semantic::appLog().trace() << "==========="; send(iot::mqtt_fast::packets::Suback(packetIdentifier, returnCodes)); } void SocketContext::sendUnsubscribe(std::list& topics) { - LOG(TRACE) << "Send UNSUBSCRIBE"; - LOG(TRACE) << "================"; + snode::semantic::appLog().trace() << "Send UNSUBSCRIBE"; + snode::semantic::appLog().trace() << "================"; send(iot::mqtt_fast::packets::Unsubscribe(getPacketIdentifier(), topics)); } void SocketContext::sendUnsuback(uint16_t packetIdentifier) { - LOG(TRACE) << "Send UNSUBACK"; - LOG(TRACE) << "============="; + snode::semantic::appLog().trace() << "Send UNSUBACK"; + snode::semantic::appLog().trace() << "============="; send(iot::mqtt_fast::packets::Unsuback(packetIdentifier)); } void SocketContext::sendPingreq() { - LOG(TRACE) << "Send Pingreq"; - LOG(TRACE) << "============"; + snode::semantic::appLog().trace() << "Send Pingreq"; + snode::semantic::appLog().trace() << "============"; send(iot::mqtt_fast::packets::Pingreq()); } void SocketContext::sendPingresp() { - LOG(TRACE) << "Send Pingresp"; - LOG(TRACE) << "============="; + snode::semantic::appLog().trace() << "Send Pingresp"; + snode::semantic::appLog().trace() << "============="; send(iot::mqtt_fast::packets::Pingresp()); } void SocketContext::sendDisconnect() { - LOG(TRACE) << "Send Disconnect"; - LOG(TRACE) << "==============="; + snode::semantic::appLog().trace() << "Send Disconnect"; + snode::semantic::appLog().trace() << "==============="; send(iot::mqtt_fast::packets::Disconnect()); } @@ -140,13 +141,13 @@ namespace iot::mqtt_fast { std::size_t consumed = controlPacketFactory.construct(); if (controlPacketFactory.isError()) { - LOG(ERROR) << "SocketContext: Error during ControlPacket construction"; + snode::semantic::appLog().error() << "SocketContext: Error during ControlPacket construction"; close(); } else if (controlPacketFactory.isComplete()) { - LOG(TRACE) << "======================================================"; - LOG(TRACE) << "PacketType: " << static_cast(controlPacketFactory.getPacketType()); - LOG(TRACE) << "PacketFlags: " << static_cast(controlPacketFactory.getPacketFlags()); - LOG(TRACE) << "RemainingLength: " << static_cast(controlPacketFactory.getRemainingLength()); + snode::semantic::appLog().trace() << "======================================================"; + snode::semantic::appLog().trace() << "PacketType: " << static_cast(controlPacketFactory.getPacketType()); + snode::semantic::appLog().trace() << "PacketFlags: " << static_cast(controlPacketFactory.getPacketFlags()); + snode::semantic::appLog().trace() << "RemainingLength: " << static_cast(controlPacketFactory.getRemainingLength()); printData(controlPacketFactory.getPacket().getValue()); @@ -232,7 +233,7 @@ namespace iot::mqtt_fast { << " "; // << " | "; } - LOG(TRACE) << ss.str(); + snode::semantic::appLog().trace() << ss.str(); } } // namespace iot::mqtt_fast diff --git a/src/iot/mqtt/Mqtt.cpp b/src/iot/mqtt/Mqtt.cpp index 20dcb96c55..f053cb5ae0 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) 2020, 2021, 2022, 2023 Volker Christian @@ -71,24 +72,24 @@ namespace iot::mqtt { break; } - LOG(TRACE) << "======================================================"; - LOG(TRACE) << "Fixed Header: PacketType: 0x" << std::hex << std::setfill('0') << std::setw(2) + snode::semantic::appLog().trace() << "======================================================"; + snode::semantic::appLog().trace() << "Fixed Header: PacketType: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(fixedHeader.getPacketType()); - LOG(TRACE) << " PacketFlags: 0x" << std::hex << std::setfill('0') << std::setw(2) + snode::semantic::appLog().trace() << " PacketFlags: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(fixedHeader.getFlags()) << std::dec; - LOG(TRACE) << " RemainingLength: " << fixedHeader.getRemainingLength(); + snode::semantic::appLog().trace() << " RemainingLength: " << fixedHeader.getRemainingLength(); controlPacketDeserializer = createControlPacketDeserializer(fixedHeader); fixedHeader.reset(); if (controlPacketDeserializer == nullptr) { - LOG(TRACE) << "Received packet-type is unavailable ... closing connection"; + snode::semantic::appLog().trace() << "Received packet-type is unavailable ... closing connection"; mqttContext->end(true); break; } else if (controlPacketDeserializer->isError()) { - LOG(TRACE) << "Fixed header has error ... closing connection"; + snode::semantic::appLog().trace() << "Fixed header has error ... closing connection"; delete controlPacketDeserializer; controlPacketDeserializer = nullptr; @@ -112,7 +113,7 @@ namespace iot::mqtt { keepAliveTimer.restart(); } else if (controlPacketDeserializer->isError()) { - LOG(TRACE) << "Control packet has error ... closing connection"; + snode::semantic::appLog().trace() << "Control packet has error ... closing connection"; mqttContext->end(true); delete controlPacketDeserializer; @@ -141,15 +142,15 @@ namespace iot::mqtt { this->session = session; for (auto& [packetIdentifier, publish] : session->publishMap) { - LOG(DEBUG) << "Resend PUBLISH"; - LOG(DEBUG) << "=============="; + snode::semantic::appLog().debug() << "Resend PUBLISH"; + snode::semantic::appLog().debug() << "=============="; send(publish); } for (uint16_t packetIdentifier : session->pubrelPacketIdentifierSet) { - LOG(DEBUG) << "Resend PUBREL"; - LOG(DEBUG) << "============="; + snode::semantic::appLog().debug() << "Resend PUBREL"; + snode::semantic::appLog().debug() << "============="; send(iot::mqtt::packets::Pubrel(packetIdentifier)); } @@ -157,7 +158,7 @@ namespace iot::mqtt { if (keepAlive > 0) { keepAliveTimer = core::timer::Timer::singleshotTimer( [this, keepAlive]() -> void { - LOG(TRACE) << "Keep-alive timer expired. Interval was: " << keepAlive; + snode::semantic::appLog().trace() << "Keep-alive timer expired. Interval was: " << keepAlive; mqttContext->close(); }, keepAlive); @@ -171,15 +172,15 @@ namespace iot::mqtt { } void Mqtt::send(const std::vector& data) const { - LOG(DEBUG) << dataToHexString(data); + snode::semantic::appLog().debug() << dataToHexString(data); mqttContext->send(data.data(), data.size()); } void Mqtt::sendPublish(const std::string& topic, const std::string& message, uint8_t qoS, bool retain) { // Server & Client - LOG(DEBUG) << "Send PUBLISH"; - LOG(DEBUG) << "============"; + snode::semantic::appLog().debug() << "Send PUBLISH"; + snode::semantic::appLog().debug() << "============"; uint16_t pId = qoS != 0 ? getPacketIdentifier() : 0; @@ -191,29 +192,29 @@ namespace iot::mqtt { } void Mqtt::sendPuback(uint16_t packetIdentifier) const { // Server & Client - LOG(DEBUG) << "Send PUBACK"; - LOG(DEBUG) << "==========="; + snode::semantic::appLog().debug() << "Send PUBACK"; + snode::semantic::appLog().debug() << "==========="; send(iot::mqtt::packets::Puback(packetIdentifier)); } void Mqtt::sendPubrec(uint16_t packetIdentifier) const { // Server & Client - LOG(DEBUG) << "Send PUBREC"; - LOG(DEBUG) << "==========="; + snode::semantic::appLog().debug() << "Send PUBREC"; + snode::semantic::appLog().debug() << "==========="; send(iot::mqtt::packets::Pubrec(packetIdentifier)); } void Mqtt::sendPubrel(uint16_t packetIdentifier) const { // Server & Client - LOG(DEBUG) << "Send PUBREL"; - LOG(DEBUG) << "==========="; + snode::semantic::appLog().debug() << "Send PUBREL"; + snode::semantic::appLog().debug() << "==========="; send(iot::mqtt::packets::Pubrel(packetIdentifier)); } void Mqtt::sendPubcomp(uint16_t packetIdentifier) const { // Server & Client - LOG(DEBUG) << "Send PUBCOMP"; - LOG(DEBUG) << "============"; + snode::semantic::appLog().debug() << "Send PUBCOMP"; + snode::semantic::appLog().debug() << "============"; send(iot::mqtt::packets::Pubcomp(packetIdentifier)); } @@ -236,19 +237,19 @@ namespace iot::mqtt { bool Mqtt::_onPublish(const packets::Publish& publish) { bool deliver = true; printStandardHeader(publish); - LOG(DEBUG) << "Topic: " << publish.getTopic(); - LOG(DEBUG) << "Message: " << publish.getMessage(); - LOG(DEBUG) << "QoS: " << static_cast(publish.getQoS()); - LOG(DEBUG) << "PacketIdentifier: " << publish.getPacketIdentifier(); - LOG(DEBUG) << "DUP: " << publish.getDup(); - LOG(DEBUG) << "Retain: " << publish.getRetain(); + snode::semantic::appLog().debug() << "Topic: " << publish.getTopic(); + snode::semantic::appLog().debug() << "Message: " << publish.getMessage(); + snode::semantic::appLog().debug() << "QoS: " << static_cast(publish.getQoS()); + snode::semantic::appLog().debug() << "PacketIdentifier: " << publish.getPacketIdentifier(); + snode::semantic::appLog().debug() << "DUP: " << publish.getDup(); + snode::semantic::appLog().debug() << "Retain: " << publish.getRetain(); if (publish.getQoS() > 2) { - LOG(TRACE) << "Received invalid QoS: " << publish.getQoS(); + snode::semantic::appLog().trace() << "Received invalid QoS: " << publish.getQoS(); mqttContext->end(true); deliver = false; } else if (publish.getPacketIdentifier() == 0 && publish.getQoS() > 0) { - LOG(TRACE) << "Received QoS > 0 but no PackageIdentifier present"; + snode::semantic::appLog().trace() << "Received QoS > 0 but no PackageIdentifier present"; mqttContext->end(true); deliver = false; } else { @@ -273,13 +274,13 @@ namespace iot::mqtt { return deliver; } void Mqtt::_onPuback(const iot::mqtt::packets::Puback& puback) { - LOG(DEBUG) << "Received PUBACK:"; - LOG(DEBUG) << "================"; + snode::semantic::appLog().debug() << "Received PUBACK:"; + snode::semantic::appLog().debug() << "================"; printStandardHeader(puback); - LOG(DEBUG) << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << puback.getPacketIdentifier(); + snode::semantic::appLog().debug() << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << puback.getPacketIdentifier(); if (puback.getPacketIdentifier() == 0) { - LOG(TRACE) << "PackageIdentifier missing"; + snode::semantic::appLog().trace() << "PackageIdentifier missing"; mqttContext->end(true); } @@ -287,13 +288,13 @@ namespace iot::mqtt { } void Mqtt::_onPubrec(const iot::mqtt::packets::Pubrec& pubrec) { - LOG(DEBUG) << "Received PUBREC:"; - LOG(DEBUG) << "================"; + snode::semantic::appLog().debug() << "Received PUBREC:"; + snode::semantic::appLog().debug() << "================"; printStandardHeader(pubrec); - LOG(DEBUG) << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << pubrec.getPacketIdentifier(); + snode::semantic::appLog().debug() << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << pubrec.getPacketIdentifier(); if (pubrec.getPacketIdentifier() == 0) { - LOG(TRACE) << "PackageIdentifier missing"; + snode::semantic::appLog().trace() << "PackageIdentifier missing"; mqttContext->end(true); } else { session->publishMap.erase(pubrec.getPacketIdentifier()); @@ -306,13 +307,13 @@ namespace iot::mqtt { } void Mqtt::_onPubrel(const iot::mqtt::packets::Pubrel& pubrel) { - LOG(DEBUG) << "Received PUBREL:"; - LOG(DEBUG) << "================"; + snode::semantic::appLog().debug() << "Received PUBREL:"; + snode::semantic::appLog().debug() << "================"; printStandardHeader(pubrel); - LOG(DEBUG) << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << pubrel.getPacketIdentifier(); + snode::semantic::appLog().debug() << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << pubrel.getPacketIdentifier(); if (pubrel.getPacketIdentifier() == 0) { - LOG(TRACE) << "PackageIdentifier missing"; + snode::semantic::appLog().trace() << "PackageIdentifier missing"; mqttContext->end(true); } else { session->publishPacketIdentifierSet.erase(pubrel.getPacketIdentifier()); @@ -324,13 +325,13 @@ namespace iot::mqtt { } void Mqtt::_onPubcomp(const iot::mqtt::packets::Pubcomp& pubcomp) { - LOG(DEBUG) << "Received PUBCOMP:"; - LOG(DEBUG) << "================="; + snode::semantic::appLog().debug() << "Received PUBCOMP:"; + snode::semantic::appLog().debug() << "================="; printStandardHeader(pubcomp); - LOG(DEBUG) << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << pubcomp.getPacketIdentifier(); + snode::semantic::appLog().debug() << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << pubcomp.getPacketIdentifier(); if (pubcomp.getPacketIdentifier() == 0) { - LOG(TRACE) << "PackageIdentifier missing"; + snode::semantic::appLog().trace() << "PackageIdentifier missing"; mqttContext->end(true); } else { session->publishMap.erase(pubcomp.getPacketIdentifier()); @@ -341,11 +342,11 @@ namespace iot::mqtt { } void Mqtt::printStandardHeader(const iot::mqtt::ControlPacket& packet) { - LOG(DEBUG) << dataToHexString(packet.serialize()); + snode::semantic::appLog().debug() << dataToHexString(packet.serialize()); - LOG(DEBUG) << "Type: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(packet.getType()); - LOG(DEBUG) << "Flags: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(packet.getFlags()); - LOG(DEBUG) << "RemainingLength: " << std::dec << dynamic_cast(packet).getRemainingLength(); + snode::semantic::appLog().debug() << "Type: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(packet.getType()); + snode::semantic::appLog().debug() << "Flags: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(packet.getFlags()); + snode::semantic::appLog().debug() << "RemainingLength: " << std::dec << dynamic_cast(packet).getRemainingLength(); } std::string Mqtt::dataToHexString(const std::vector& data) { diff --git a/src/iot/mqtt/SubProtocol.hpp b/src/iot/mqtt/SubProtocol.hpp index 228c308fe8..e92a5fd717 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) 2020, 2021, 2022, 2023 Volker Christian @@ -79,17 +80,17 @@ namespace iot::mqtt { template void SubProtocol::onConnected() { - LOG(INFO) << "Mqtt connected:"; + snode::semantic::appLog().info() << "Mqtt connected:"; iot::mqtt::MqttContext::onConnected(); } template void SubProtocol::onMessageStart(int opCode) { if (opCode == web::websocket::SubProtocolContext::OpCode::TEXT) { - LOG(ERROR) << "WebSocket: Wrong Opcode: " << opCode; + snode::semantic::appLog().error() << "WebSocket: Wrong Opcode: " << opCode; this->end(true); } else { - LOG(TRACE) << "WebSocket: Message START: " << opCode; + snode::semantic::appLog().trace() << "WebSocket: Message START: " << opCode; } } @@ -110,12 +111,12 @@ namespace iot::mqtt { ss << "0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(static_cast(ch)) << " "; // << " | "; } - LOG(TRACE) << ss.str(); + snode::semantic::appLog().trace() << ss.str(); } template void SubProtocol::onMessageEnd() { - LOG(TRACE) << "WebSocket: Message END"; + snode::semantic::appLog().trace() << "WebSocket: Message END"; buffer.insert(buffer.end(), data.begin(), data.end()); size += data.size(); @@ -128,18 +129,18 @@ namespace iot::mqtt { template void SubProtocol::onMessageError(uint16_t errnum) { - LOG(ERROR) << "WebSocket: Message error: " << errnum; + snode::semantic::appLog().error() << "WebSocket: Message error: " << errnum; } template void SubProtocol::onDisconnected() { - LOG(INFO) << "MQTT disconnected:"; + snode::semantic::appLog().info() << "MQTT disconnected:"; iot::mqtt::MqttContext::onDisconnected(); } template void SubProtocol::onExit() { - LOG(INFO) << "MQTT exit"; + snode::semantic::appLog().info() << "MQTT exit"; iot::mqtt::MqttContext::onExit(); this->sendClose(); } diff --git a/src/iot/mqtt/client/Mqtt.cpp b/src/iot/mqtt/client/Mqtt.cpp index 736eab14e6..dd465cc227 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) 2020, 2021, 2022, 2023 Volker Christian @@ -63,19 +64,19 @@ namespace iot::mqtt::client { session.fromJson(sessionStoreJson); - LOG(TRACE) << "Persistent session data loaded successfull"; + snode::semantic::appLog().trace() << "Persistent session data loaded successfull"; } catch (const nlohmann::json::exception&) { - LOG(TRACE) << "Starting with empty session: Session store '" << sessionStoreFileName << "' empty or corrupted"; + snode::semantic::appLog().trace() << "Starting with empty session: Session store '" << sessionStoreFileName << "' empty or corrupted"; session.clear(); } sessionStoreFile.close(); std::remove(sessionStoreFileName.data()); } else { - PLOG(TRACE) << "Could not read session store '" << sessionStoreFileName << "'"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Trace, errno) << "Could not read session store '" << sessionStoreFileName << "'"; } } else { - LOG(INFO) << "Session not reloaded: Session store filename empty"; + snode::semantic::appLog().info() << "Session not reloaded: Session store filename empty"; } } @@ -92,10 +93,10 @@ namespace iot::mqtt::client { sessionStoreFile.close(); } else { - PLOG(TRACE) << "Could not write session store '" << sessionStoreFileName << "'"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Trace, errno) << "Could not write session store '" << sessionStoreFileName << "'"; } } else { - LOG(INFO) << "Session not saved: Session store filename empty"; + snode::semantic::appLog().info() << "Session not saved: Session store filename empty"; } pingTimer.cancel(); @@ -157,15 +158,15 @@ namespace iot::mqtt::client { } void Mqtt::_onConnack(const iot::mqtt::client::packets::Connack& connack) { - LOG(DEBUG) << "Received Connack:"; - LOG(DEBUG) << "================="; + snode::semantic::appLog().debug() << "Received Connack:"; + snode::semantic::appLog().debug() << "================="; printStandardHeader(connack); - LOG(DEBUG) << "Acknowledge Flag: " << static_cast(connack.getAcknowledgeFlags()); - LOG(DEBUG) << "Return code: " << static_cast(connack.getReturnCode()); - LOG(DEBUG) << "Session present: " << connack.getSessionPresent(); + snode::semantic::appLog().debug() << "Acknowledge Flag: " << static_cast(connack.getAcknowledgeFlags()); + snode::semantic::appLog().debug() << "Return code: " << static_cast(connack.getReturnCode()); + snode::semantic::appLog().debug() << "Session present: " << connack.getSessionPresent(); if (connack.getReturnCode() != MQTT_CONNACK_ACCEPT) { - LOG(TRACE) << "Negative ack received"; + snode::semantic::appLog().trace() << "Negative ack received"; mqttContext->end(true); } else { initSession(&session, keepAlive * 2); @@ -181,8 +182,8 @@ namespace iot::mqtt::client { } void Mqtt::_onPublish(const iot::mqtt::client::packets::Publish& publish) { - LOG(DEBUG) << "Received PUBLISH:"; - LOG(DEBUG) << "================="; + snode::semantic::appLog().debug() << "Received PUBLISH:"; + snode::semantic::appLog().debug() << "================="; if (Super::_onPublish(publish)) { onPublish(publish); @@ -190,10 +191,10 @@ namespace iot::mqtt::client { } void Mqtt::_onSuback(const iot::mqtt::client::packets::Suback& suback) { - LOG(DEBUG) << "Received SUBACK:"; - LOG(DEBUG) << "================"; + snode::semantic::appLog().debug() << "Received SUBACK:"; + snode::semantic::appLog().debug() << "================"; printStandardHeader(suback); - LOG(DEBUG) << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << suback.getPacketIdentifier(); + snode::semantic::appLog().debug() << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << suback.getPacketIdentifier(); std::stringstream ss; std::list::size_type i = 0; @@ -207,10 +208,10 @@ namespace iot::mqtt::client { ss << "0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(returnCode) << " "; // << " | "; } - LOG(DEBUG) << "Return codes: " << ss.str(); + snode::semantic::appLog().debug() << "Return codes: " << ss.str(); if (suback.getPacketIdentifier() == 0) { - LOG(TRACE) << "PackageIdentifier missing"; + snode::semantic::appLog().trace() << "PackageIdentifier missing"; mqttContext->end(true); } else { onSuback(suback); @@ -218,13 +219,13 @@ namespace iot::mqtt::client { } void Mqtt::_onUnsuback(const iot::mqtt::client::packets::Unsuback& unsuback) { - LOG(DEBUG) << "Received UNSUBACK:"; - LOG(DEBUG) << "=================="; + snode::semantic::appLog().debug() << "Received UNSUBACK:"; + snode::semantic::appLog().debug() << "=================="; printStandardHeader(unsuback); - LOG(DEBUG) << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << unsuback.getPacketIdentifier(); + snode::semantic::appLog().debug() << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << unsuback.getPacketIdentifier(); if (unsuback.getPacketIdentifier() == 0) { - LOG(TRACE) << "PackageIdentifier missing"; + snode::semantic::appLog().trace() << "PackageIdentifier missing"; mqttContext->end(true); } else { onUnsuback(unsuback); @@ -232,8 +233,8 @@ namespace iot::mqtt::client { } void Mqtt::_onPingresp(const iot::mqtt::client::packets::Pingresp& pingresp) { - LOG(DEBUG) << "Received PINGRESP:"; - LOG(DEBUG) << "=================="; + snode::semantic::appLog().debug() << "Received PINGRESP:"; + snode::semantic::appLog().debug() << "=================="; printStandardHeader(pingresp); onPingresp(pingresp); @@ -248,8 +249,8 @@ namespace iot::mqtt::client { bool willRetain, const std::string& username, const std::string& password) { // Client - LOG(DEBUG) << "Send CONNECT"; - LOG(DEBUG) << "============"; + snode::semantic::appLog().debug() << "Send CONNECT"; + snode::semantic::appLog().debug() << "============"; send(iot::mqtt::packets::Connect( clientId, keepAlive, cleanSession, willTopic, willMessage, willQoS, willRetain, username, password)); @@ -258,29 +259,29 @@ namespace iot::mqtt::client { } void Mqtt::sendSubscribe(std::list& topics) { // Client - LOG(DEBUG) << "Send SUBSCRIBE"; - LOG(DEBUG) << "=============="; + snode::semantic::appLog().debug() << "Send SUBSCRIBE"; + snode::semantic::appLog().debug() << "=============="; send(iot::mqtt::packets::Subscribe(getPacketIdentifier(), topics)); } void Mqtt::sendUnsubscribe(std::list& topics) { // Client - LOG(DEBUG) << "Send UNSUBSCRIBE"; - LOG(DEBUG) << "================"; + snode::semantic::appLog().debug() << "Send UNSUBSCRIBE"; + snode::semantic::appLog().debug() << "================"; send(iot::mqtt::packets::Unsubscribe(getPacketIdentifier(), topics)); } void Mqtt::sendPingreq() const { // Client - LOG(DEBUG) << "Send Pingreq"; - LOG(DEBUG) << "============"; + snode::semantic::appLog().debug() << "Send Pingreq"; + snode::semantic::appLog().debug() << "============"; send(iot::mqtt::packets::Pingreq()); } void Mqtt::sendDisconnect() const { // Client - LOG(DEBUG) << "Send Disconnect"; - LOG(DEBUG) << "==============="; + snode::semantic::appLog().debug() << "Send Disconnect"; + snode::semantic::appLog().debug() << "==============="; send(iot::mqtt::packets::Disconnect()); } diff --git a/src/iot/mqtt/server/Mqtt.cpp b/src/iot/mqtt/server/Mqtt.cpp index 002dca6060..53e6cac217 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) 2020, 2021, 2022, 2023 Volker Christian @@ -121,8 +122,8 @@ namespace iot::mqtt::server { void Mqtt::initSession(const utils::Timeval& keepAlive) { if (broker->hasActiveSession(clientId)) { - LOG(TRACE) << "Existing session found for ClientId = `" << clientId << "'"; - LOG(TRACE) << " closing"; + snode::semantic::appLog().trace() << "Existing session found for ClientId = `" << clientId << "'"; + snode::semantic::appLog().trace() << " closing"; sendConnack(MQTT_CONNACK_IDENTIFIERREJECTED, 0); @@ -132,21 +133,21 @@ namespace iot::mqtt::server { } else if (broker->hasRetainedSession(clientId)) { sendConnack(MQTT_CONNACK_ACCEPT, cleanSession ? MQTT_SESSION_NEW : MQTT_SESSION_PRESENT); - LOG(TRACE) << "Retained session found for ClientId = '" << clientId << "'"; + snode::semantic::appLog().trace() << "Retained session found for ClientId = '" << clientId << "'"; if (cleanSession) { - LOG(TRACE) << " clean Session = " << this; + snode::semantic::appLog().trace() << " clean Session = " << this; broker->unsubscribe(clientId); initSession(broker->newSession(clientId, this), keepAlive); } else { - LOG(TRACE) << " renew Session = " << this; + snode::semantic::appLog().trace() << " renew Session = " << this; initSession(broker->renewSession(clientId, this), keepAlive); broker->restartSession(clientId); } } else { sendConnack(MQTT_CONNACK_ACCEPT, MQTT_SESSION_NEW); - LOG(TRACE) << "No session found for ClientId = '" << clientId << "\'"; - LOG(TRACE) << " new Session = " << this; + snode::semantic::appLog().trace() << "No session found for ClientId = '" << clientId << "\'"; + snode::semantic::appLog().trace() << " new Session = " << this; initSession(broker->newSession(clientId, this), keepAlive); } @@ -155,10 +156,10 @@ namespace iot::mqtt::server { void Mqtt::releaseSession() { if (broker->isActiveSession(clientId, this)) { if (cleanSession) { - LOG(DEBUG) << "Delete session: " << clientId; + snode::semantic::appLog().debug() << "Delete session: " << clientId; broker->deleteSession(clientId); } else { - LOG(DEBUG) << "Retain session: " << clientId; + snode::semantic::appLog().debug() << "Retain session: " << clientId; broker->retainSession(clientId); } } @@ -180,40 +181,40 @@ namespace iot::mqtt::server { } void Mqtt::_onConnect(const iot::mqtt::server::packets::Connect& connect) { - LOG(DEBUG) << "Received CONNECT: " << clientId; - LOG(DEBUG) << "================="; + snode::semantic::appLog().debug() << "Received CONNECT: " << clientId; + snode::semantic::appLog().debug() << "================="; printStandardHeader(connect); - LOG(DEBUG) << "Protocol: " << connect.getProtocol(); - LOG(DEBUG) << "Version: " << static_cast(connect.getLevel()); - LOG(DEBUG) << "ConnectFlags: 0x" << std::hex << std::setfill('0') << std::setw(2) + snode::semantic::appLog().debug() << "Protocol: " << connect.getProtocol(); + snode::semantic::appLog().debug() << "Version: " << static_cast(connect.getLevel()); + snode::semantic::appLog().debug() << "ConnectFlags: 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast(connect.getConnectFlags()) << std::dec << std::setw(0); - LOG(DEBUG) << "KeepAlive: " << connect.getKeepAlive(); - LOG(DEBUG) << "ClientID: " << connect.getClientId(); - LOG(DEBUG) << "CleanSession: " << connect.getCleanSession(); + snode::semantic::appLog().debug() << "KeepAlive: " << connect.getKeepAlive(); + snode::semantic::appLog().debug() << "ClientID: " << connect.getClientId(); + snode::semantic::appLog().debug() << "CleanSession: " << connect.getCleanSession(); if (connect.getWillFlag()) { - LOG(DEBUG) << "WillTopic: " << connect.getWillTopic(); - LOG(DEBUG) << "WillMessage: " << connect.getWillMessage(); - LOG(DEBUG) << "WillQoS: " << static_cast(connect.getWillQoS()); - LOG(DEBUG) << "WillRetain: " << connect.getWillRetain(); + snode::semantic::appLog().debug() << "WillTopic: " << connect.getWillTopic(); + snode::semantic::appLog().debug() << "WillMessage: " << connect.getWillMessage(); + snode::semantic::appLog().debug() << "WillQoS: " << static_cast(connect.getWillQoS()); + snode::semantic::appLog().debug() << "WillRetain: " << connect.getWillRetain(); } if (connect.getUsernameFlag()) { - LOG(DEBUG) << "Username: " << connect.getUsername(); + snode::semantic::appLog().debug() << "Username: " << connect.getUsername(); } if (connect.getPasswordFlag()) { - LOG(DEBUG) << "Password: " << connect.getPassword(); + snode::semantic::appLog().debug() << "Password: " << connect.getPassword(); } if (connect.getProtocol() != "MQTT") { - LOG(TRACE) << "Wrong Protocol: " << connect.getProtocol(); + snode::semantic::appLog().trace() << "Wrong Protocol: " << connect.getProtocol(); mqttContext->end(true); } else if (connect.getLevel() != MQTT_VERSION_3_1_1) { - LOG(TRACE) << "Wrong Protocol Level: " << MQTT_VERSION_3_1_1 << " != " << connect.getLevel(); + snode::semantic::appLog().trace() << "Wrong Protocol Level: " << MQTT_VERSION_3_1_1 << " != " << connect.getLevel(); sendConnack(MQTT_CONNACK_UNACEPTABLEVERSION, MQTT_SESSION_NEW); mqttContext->end(true); } else if (connect.isFakedClientId() && !connect.getCleanSession()) { - LOG(TRACE) << "Resume session but no ClientId present"; + snode::semantic::appLog().trace() << "Resume session but no ClientId present"; sendConnack(MQTT_CONNACK_IDENTIFIERREJECTED, MQTT_SESSION_NEW); mqttContext->end(true); @@ -246,8 +247,8 @@ namespace iot::mqtt::server { } void Mqtt::_onPublish(const iot::mqtt::server::packets::Publish& publish) { - LOG(DEBUG) << "Received PUBLISH: " << clientId; - LOG(DEBUG) << "================="; + snode::semantic::appLog().debug() << "Received PUBLISH: " << clientId; + snode::semantic::appLog().debug() << "================="; if (Super::_onPublish(publish)) { broker->publish(publish.getTopic(), publish.getMessage(), publish.getQoS(), publish.getRetain()); @@ -257,17 +258,17 @@ namespace iot::mqtt::server { } void Mqtt::_onSubscribe(const iot::mqtt::server::packets::Subscribe& subscribe) { - LOG(DEBUG) << "Received SUBSCRIBE: " << clientId; - LOG(DEBUG) << "==================="; + snode::semantic::appLog().debug() << "Received SUBSCRIBE: " << clientId; + snode::semantic::appLog().debug() << "==================="; printStandardHeader(subscribe); - LOG(DEBUG) << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << subscribe.getPacketIdentifier(); + snode::semantic::appLog().debug() << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << subscribe.getPacketIdentifier(); for (const iot::mqtt::Topic& topic : subscribe.getTopics()) { - LOG(DEBUG) << " Topic filter: '" << topic.getName() << "', QoS: " << static_cast(topic.getQoS()); + snode::semantic::appLog().debug() << " Topic filter: '" << topic.getName() << "', QoS: " << static_cast(topic.getQoS()); } if (subscribe.getPacketIdentifier() == 0) { - LOG(TRACE) << "PackageIdentifier missing"; + snode::semantic::appLog().trace() << "PackageIdentifier missing"; mqttContext->end(true); } else { std::list returnCodes; @@ -283,17 +284,17 @@ namespace iot::mqtt::server { } void Mqtt::_onUnsubscribe(const iot::mqtt::server::packets::Unsubscribe& unsubscribe) { - LOG(DEBUG) << "Received UNSUBSCRIBE: " << clientId; - LOG(DEBUG) << "====================="; + snode::semantic::appLog().debug() << "Received UNSUBSCRIBE: " << clientId; + snode::semantic::appLog().debug() << "====================="; printStandardHeader(unsubscribe); - LOG(DEBUG) << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << unsubscribe.getPacketIdentifier(); + snode::semantic::appLog().debug() << "PacketIdentifier: 0x" << std::hex << std::setfill('0') << std::setw(4) << unsubscribe.getPacketIdentifier(); for (const std::string& topic : unsubscribe.getTopics()) { - LOG(DEBUG) << " Topic: " << topic; + snode::semantic::appLog().debug() << " Topic: " << topic; } if (unsubscribe.getPacketIdentifier() == 0) { - LOG(TRACE) << "PackageIdentifier missing"; + snode::semantic::appLog().trace() << "PackageIdentifier missing"; mqttContext->end(true); } else { for (const std::string& topic : unsubscribe.getTopics()) { @@ -307,8 +308,8 @@ namespace iot::mqtt::server { } void Mqtt::_onPingreq(const iot::mqtt::server::packets::Pingreq& pingreq) { - LOG(DEBUG) << "Received PINGREQ: " << clientId; - LOG(DEBUG) << "================="; + snode::semantic::appLog().debug() << "Received PINGREQ: " << clientId; + snode::semantic::appLog().debug() << "================="; printStandardHeader(pingreq); sendPingresp(); @@ -317,8 +318,8 @@ namespace iot::mqtt::server { } void Mqtt::_onDisconnect(const iot::mqtt::server::packets::Disconnect& disconnect) { - LOG(DEBUG) << "Received DISCONNECT: " << clientId; - LOG(DEBUG) << "===================="; + snode::semantic::appLog().debug() << "Received DISCONNECT: " << clientId; + snode::semantic::appLog().debug() << "===================="; printStandardHeader(disconnect); willFlag = false; @@ -331,29 +332,29 @@ namespace iot::mqtt::server { } void Mqtt::sendConnack(uint8_t returnCode, uint8_t flags) const { // Server - LOG(DEBUG) << "Send CONNACK"; - LOG(DEBUG) << "============"; + snode::semantic::appLog().debug() << "Send CONNACK"; + snode::semantic::appLog().debug() << "============"; send(iot::mqtt::packets::Connack(returnCode, flags)); } void Mqtt::sendSuback(uint16_t packetIdentifier, std::list& returnCodes) const { // Server - LOG(DEBUG) << "Send SUBACK"; - LOG(DEBUG) << "==========="; + snode::semantic::appLog().debug() << "Send SUBACK"; + snode::semantic::appLog().debug() << "==========="; send(iot::mqtt::packets::Suback(packetIdentifier, returnCodes)); } void Mqtt::sendUnsuback(uint16_t packetIdentifier) const { // Server - LOG(DEBUG) << "Send UNSUBACK"; - LOG(DEBUG) << "============="; + snode::semantic::appLog().debug() << "Send UNSUBACK"; + snode::semantic::appLog().debug() << "============="; send(iot::mqtt::packets::Unsuback(packetIdentifier)); } void Mqtt::sendPingresp() const { // Server - LOG(DEBUG) << "Send Pingresp"; - LOG(DEBUG) << "============="; + snode::semantic::appLog().debug() << "Send Pingresp"; + snode::semantic::appLog().debug() << "============="; send(iot::mqtt::packets::Pingresp()); } diff --git a/src/iot/mqtt/server/broker/Broker.cpp b/src/iot/mqtt/server/broker/Broker.cpp index f80d3929f4..d2cafe63ee 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) 2020, 2021, 2022, 2023 Volker Christian @@ -57,9 +58,9 @@ namespace iot::mqtt::server::broker { retainTree.fromJson(sessionStoreJson["retain_tree"]); subscribtionTree.fromJson(sessionStoreJson["subscribtion_tree"]); - LOG(TRACE) << "Persistent session data loaded successfull"; + snode::semantic::appLog().trace() << "Persistent session data loaded successfull"; } catch (const nlohmann::json::exception&) { - LOG(TRACE) << "Starting with empty session: Session store '" << sessionStoreFileName << "' empty or corrupted"; + snode::semantic::appLog().trace() << "Starting with empty session: Session store '" << sessionStoreFileName << "' empty or corrupted"; sessionStore.clear(); retainTree.clear(); @@ -69,10 +70,10 @@ namespace iot::mqtt::server::broker { sessionStoreFile.close(); std::remove(sessionStoreFileName.data()); } else { - PLOG(TRACE) << "Could not read session store '" << sessionStoreFileName << "'"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Trace, errno) << "Could not read session store '" << sessionStoreFileName << "'"; } } else { - LOG(INFO) << "Session not reloaded: Session store filename empty"; + snode::semantic::appLog().info() << "Session not reloaded: Session store filename empty"; } } @@ -105,10 +106,10 @@ namespace iot::mqtt::server::broker { sessionStoreFile.close(); } else { - PLOG(TRACE) << "Could not write session store '" << sessionStoreFileName << "'"; + snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Trace, errno) << "Could not write session store '" << sessionStoreFileName << "'"; } } else { - LOG(INFO) << "Session not saved: Session store filename empty"; + snode::semantic::appLog().info() << "Session not saved: Session store filename empty"; } } @@ -180,10 +181,10 @@ namespace iot::mqtt::server::broker { } void Broker::restartSession(const std::string& clientId) { - LOG(TRACE) << " Retained: Send Publish: ClientId: " << clientId; + snode::semantic::appLog().trace() << " Retained: Send Publish: ClientId: " << clientId; subscribtionTree.appear(clientId); - LOG(TRACE) << " Queued: Send Publish: ClientId: " << clientId; + snode::semantic::appLog().trace() << " Queued: Send Publish: ClientId: " << clientId; sessionStore[clientId].publishQueued(); } @@ -197,7 +198,7 @@ namespace iot::mqtt::server::broker { } void Broker::sendPublish(const std::string& clientId, Message& message, uint8_t qoS, bool retain) { - LOG(TRACE) << " Send Publish: ClientId: " << clientId; + snode::semantic::appLog().trace() << " Send Publish: ClientId: " << 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 5373e32d0e..3c66ac7207 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) 2020, 2021, 2022, 2023 Volker Christian @@ -81,7 +82,7 @@ namespace iot::mqtt::server::broker { bool RetainTree::TopicLevel::retain(const Message& message, std::string topic, bool appeared) { if (appeared) { if (!message.getTopic().empty()) { - LOG(TRACE) << "Retaining: " << message.getTopic() << " - " << message.getMessage(); + snode::semantic::appLog().trace() << "Retaining: " << message.getTopic() << " - " << message.getMessage(); this->message = message; } } else { @@ -107,11 +108,11 @@ namespace iot::mqtt::server::broker { void RetainTree::TopicLevel::appear(const std::string& clientId, std::string topic, uint8_t qoS, bool appeared) { if (appeared) { if (!message.getMessage().empty()) { - LOG(TRACE) << "Retained message found: " << message.getTopic() << " - " << message.getMessage() << " - " + snode::semantic::appLog().trace() << "Retained message found: " << message.getTopic() << " - " << message.getMessage() << " - " << static_cast(message.getQoS()); - LOG(TRACE) << " distribute message ..."; + snode::semantic::appLog().trace() << " distribute message ..."; broker->sendPublish(clientId, message, qoS, true); - LOG(TRACE) << " ... completed!"; + snode::semantic::appLog().trace() << " ... completed!"; } } else { std::string::size_type slashPosition = topic.find('/'); @@ -136,11 +137,11 @@ namespace iot::mqtt::server::broker { void RetainTree::TopicLevel::appear(const std::string& clientId, uint8_t clientQoS) { if (!message.getTopic().empty()) { - LOG(TRACE) << "Retained message found: " << message.getTopic() << " - " << message.getMessage() << " - " + snode::semantic::appLog().trace() << "Retained message found: " << message.getTopic() << " - " << message.getMessage() << " - " << static_cast(message.getQoS()); - LOG(TRACE) << " distribute message ..."; + snode::semantic::appLog().trace() << " distribute message ..."; broker->sendPublish(clientId, message, clientQoS, true); - LOG(TRACE) << " ... completed!"; + snode::semantic::appLog().trace() << " ... completed!"; } for (auto& [topicLevel, topicTree] : subTopicLevels) { diff --git a/src/iot/mqtt/server/broker/Session.cpp b/src/iot/mqtt/server/broker/Session.cpp index eec1fb64fa..166a1ebe00 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) 2020, 2021, 2022, 2023 Volker Christian @@ -55,9 +56,9 @@ namespace iot::mqtt::server::broker { << " "; // << " | "; } - LOG(TRACE) << " TopicName: " << message.getTopic(); - LOG(TRACE) << " Message: " << messageData.str(); - LOG(TRACE) << " QoS: " << static_cast(std::min(qoS, message.getQoS())); + snode::semantic::appLog().trace() << " TopicName: " << message.getTopic(); + snode::semantic::appLog().trace() << " Message: " << messageData.str(); + snode::semantic::appLog().trace() << " QoS: " << static_cast(std::min(qoS, message.getQoS())); if (isActive()) { mqtt->sendPublish(message.getTopic(), message.getMessage(), std::min(message.getQoS(), qoS), retain); @@ -72,11 +73,11 @@ namespace iot::mqtt::server::broker { } void Session::publishQueued() { - LOG(TRACE) << " send queued messages ..."; + snode::semantic::appLog().trace() << " send queued messages ..."; for (iot::mqtt::server::broker::Message& message : messageQueue) { sendPublish(message, message.getQoS(), false); } - LOG(TRACE) << " ... done"; + snode::semantic::appLog().trace() << " ... done"; messageQueue.clear(); } diff --git a/src/iot/mqtt/server/broker/SubscribtionTree.cpp b/src/iot/mqtt/server/broker/SubscribtionTree.cpp index 72a0b9f38d..2584bcd3b8 100644 --- a/src/iot/mqtt/server/broker/SubscribtionTree.cpp +++ b/src/iot/mqtt/server/broker/SubscribtionTree.cpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -101,29 +102,29 @@ namespace iot::mqtt::server::broker { void SubscribtionTree::TopicLevel::publish(Message& message, std::string topic, bool leafFound) { if (leafFound) { - LOG(TRACE) << "Found match:"; - LOG(TRACE) << " Topic: '" << message.getTopic() << "';"; - LOG(TRACE) << " Message: '" << message.getMessage() << "' "; - LOG(TRACE) << "Distribute Publish for match ..."; + snode::semantic::appLog().trace() << "Found match:"; + snode::semantic::appLog().trace() << " Topic: '" << message.getTopic() << "';"; + snode::semantic::appLog().trace() << " Message: '" << message.getMessage() << "' "; + snode::semantic::appLog().trace() << "Distribute Publish for match ..."; for (auto& [clientId, clientQoS] : subscribers) { broker->sendPublish(clientId, message, clientQoS, false); } - LOG(TRACE) << "... completed!"; + snode::semantic::appLog().trace() << "... completed!"; auto nextHashLevel = topicLevels.find("#"); if (nextHashLevel != topicLevels.end()) { - LOG(TRACE) << "Found parent match:"; - LOG(TRACE) << " Topic: '" << message.getTopic() << "'"; - LOG(TRACE) << " Message: '" << message.getMessage() << "'"; - LOG(TRACE) << "Distribute Publish for match ..."; + snode::semantic::appLog().trace() << "Found parent match:"; + snode::semantic::appLog().trace() << " Topic: '" << message.getTopic() << "'"; + snode::semantic::appLog().trace() << " Message: '" << message.getMessage() << "'"; + snode::semantic::appLog().trace() << "Distribute Publish for match ..."; for (auto& [clientId, clientQoS] : nextHashLevel->second.subscribers) { broker->sendPublish(clientId, message, clientQoS, false); } - LOG(TRACE) << "... completed!"; + snode::semantic::appLog().trace() << "... completed!"; } } else { std::string::size_type slashPosition = topic.find('/'); @@ -145,13 +146,13 @@ namespace iot::mqtt::server::broker { foundNode = topicLevels.find("#"); if (foundNode != topicLevels.end()) { - LOG(TRACE) << "Found match for topic filter: '.../" << topicLevel << "/#', topic: '" << message.getTopic() + snode::semantic::appLog().trace() << "Found match for topic filter: '.../" << topicLevel << "/#', topic: '" << message.getTopic() << "', Message: '" << message.getMessage() << "'"; - LOG(TRACE) << "Distribute Publish ..."; + snode::semantic::appLog().trace() << "Distribute Publish ..."; for (auto& [clientId, clientQoS] : foundNode->second.subscribers) { broker->sendPublish(clientId, message, clientQoS, false); } - LOG(TRACE) << "... completed!"; + snode::semantic::appLog().trace() << "... completed!"; } } } diff --git a/src/log/CMakeLists.txt b/src/log/CMakeLists.txt index 993123f881..a9ed40d296 100644 --- a/src/log/CMakeLists.txt +++ b/src/log/CMakeLists.txt @@ -67,6 +67,12 @@ install( PATTERN "easyloggingpp" EXCLUDE ) +install( + FILES "${CMAKE_CURRENT_SOURCE_DIR}/../SemanticLog.h" + DESTINATION include/snode.c + COMPONENT logger +) + install( EXPORT snodec_logger_Targets FILE snodec_logger_Targets.cmake diff --git a/src/log/Logger.cpp b/src/log/Logger.cpp index 5ba0d1fe39..a8c4fed377 100644 --- a/src/log/Logger.cpp +++ b/src/log/Logger.cpp @@ -62,7 +62,7 @@ namespace logger { el::Helpers::installCustomFormatSpecifier(el::CustomFormatSpecifier(format, resolver)); } - // Application logging should be done with VLOG(loglevel) + // Application logging uses the semantic application logger. // Framework logging should use one of the following levels void Logger::setLogLevel(int level) { conf.set(el::Level::Trace, el::ConfigurationType::Enabled, "false"); // trace method/function calling diff --git a/src/net/un/PhysicalSocket.hpp b/src/net/un/PhysicalSocket.hpp index befec5c93b..4f9594d1c5 100644 --- a/src/net/un/PhysicalSocket.hpp +++ b/src/net/un/PhysicalSocket.hpp @@ -1,3 +1,4 @@ +#include /* * snode.c - a slim toolkit for network communication * Copyright (C) 2020, 2021, 2022, 2023 Volker Christian @@ -38,7 +39,7 @@ namespace net::un { template