diff --git a/docs/logging/public-log-api.md b/docs/logging/public-log-api.md new file mode 100644 index 000000000..96801e308 --- /dev/null +++ b/docs/logging/public-log-api.md @@ -0,0 +1,33 @@ +# Public logging API + +`` is the single application-facing logging header. New code belongs in +the `snode::log` namespace and does not need the internal `logger` model or the +backend implementation. + +```cpp +#include + +auto log = snode::log::application("gateway.mqtt"); +log.info("Connected to {}", broker); +log.systemError(snode::log::Level::Error, errno, "Publish failed"); +``` + +Use `application()` for process or component diagnostics, `framework()` for +framework-owned diagnostics, `forConnection()` when a live connection is +available, and `makeLogger()` for an explicitly constructed `Scope`. `Scope` +and `Identity` own their strings, so loggers cannot retain dangling views. + +The six severity methods support both stream and `{}`-formatted forms. Escaped +braces are written as `{{` and `}}`; malformed formats and argument-count +mismatches throw `std::invalid_argument`. Formatting is skipped when the level +is disabled. `event()` adds a stable event name, `systemError()` adds a typed +error, and `emit()` accepts separate plain and terminal presentations. + +Configure logging once during startup with `configure(Settings)`. Settings +cover the global threshold, text or JSON output, color policy, quiet mode, +rotating-file output, and component or instance overrides. Configuration is +also overridable by origin and boundary and is frozen after it is applied. + +`SemanticLog.h` and the lower-level headers under `log/` remain compatibility +surfaces for existing consumers. They are implementation and migration aids; +new application code should include only ``. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 710f41c53..c6e4ee78e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -122,17 +122,6 @@ else() add_link_options(LINKER:--as-needed LINKER:--no-undefined) endif() -option(SNODEC_DISABLE_LOGLEVEL_LOGGING "Disable LOG() and PLOG() logging") -option(SNODEC_DISABLE_VERBOSE_LOGGING "Disable VLOG() logging") - -if(SNODEC_DISABLE_LOGLEVEL_LOGGING) - add_compile_definitions(SNODEC_DISABLE_LOGLEVEL_LOGGING) -endif(SNODEC_DISABLE_LOGLEVEL_LOGGING) - -if(SNODEC_DISABLE_VERBOSE_LOGGING) - add_compile_definitions(SNODEC_DISABLE_VERBOSE_LOGGING) -endif(SNODEC_DISABLE_VERBOSE_LOGGING) - add_subdirectory(log) add_subdirectory(utils) add_subdirectory(core) @@ -218,7 +207,8 @@ install( ) install( - FILES "${CMAKE_CURRENT_SOURCE_DIR}/SemanticLog.h" + FILES "${CMAKE_CURRENT_SOURCE_DIR}/Log.h" + "${CMAKE_CURRENT_SOURCE_DIR}/SemanticLog.h" DESTINATION include/snode.c COMPONENT "logger" ) diff --git a/src/Log.h b/src/Log.h new file mode 100644 index 000000000..ebad673aa --- /dev/null +++ b/src/Log.h @@ -0,0 +1,274 @@ +#ifndef SNODEC_LOG_H +#define SNODEC_LOG_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace snode::log { + + enum class Level { Trace, Debug, Info, Warning, Error, Critical, Off }; + enum class Origin { Framework, Application }; + enum class Boundary { Application, Configuration, Instance, Connection, Context, System }; + enum class Role { Server, Client }; + enum class Format { Text, Json }; + enum class ColorMode { Automatic, Always, Never }; + + struct Identity { + std::optional instance = std::nullopt; + std::optional role = std::nullopt; + std::optional connection = std::nullopt; + }; + + struct Scope { + Origin origin = Origin::Application; + Boundary boundary = Boundary::Application; + std::string component = "app"; + Identity identity; + + }; + + struct LevelOverride { + std::string name; + Level level = Level::Info; + }; + + struct OriginLevelOverride { + Origin origin = Origin::Application; + Level level = Level::Info; + }; + + struct BoundaryLevelOverride { + Boundary boundary = Boundary::Application; + Level level = Level::Info; + }; + + struct Message { + std::string plain; + std::optional terminal; + }; + + struct Settings { + Level level = Level::Info; + Format format = Format::Text; + ColorMode color = ColorMode::Automatic; + bool quiet = false; + std::optional file; + std::vector originLevels; + std::vector boundaryLevels; + std::vector componentLevels; + std::vector instanceLevels; + }; + + void configure(const Settings& settings); + + namespace detail { + template + std::string stringify(T&& value) { + std::ostringstream out; + out << std::forward(value); + return out.str(); + } + + template + std::string format(std::string_view pattern, Args&&... args) { + std::vector values; + values.reserve(sizeof...(Args)); + (values.emplace_back(stringify(std::forward(args))), ...); + + std::string result; + result.reserve(pattern.size()); + std::size_t argument = 0; + for (std::size_t index = 0; index < pattern.size(); ++index) { + if (pattern[index] == '{' && index + 1 < pattern.size()) { + if (pattern[index + 1] == '{') { + result.push_back('{'); + ++index; + continue; + } + if (pattern[index + 1] == '}') { + if (argument >= values.size()) { + throw std::invalid_argument("log format has too few arguments"); + } + result += values[argument++]; + ++index; + continue; + } + } + if (pattern[index] == '}') { + if (index + 1 < pattern.size() && pattern[index + 1] == '}') { + result.push_back('}'); + ++index; + continue; + } + throw std::invalid_argument("log format contains an unmatched '}'"); + } + if (pattern[index] == '{') { + throw std::invalid_argument("log format contains an unmatched '{'"); + } + result.push_back(pattern[index]); + } + if (argument != values.size()) { + throw std::invalid_argument("log format has too many arguments"); + } + return result; + } + } // namespace detail + + class Logger; + + class Stream { + public: + Stream(Stream&&) noexcept; + Stream& operator=(Stream&&) noexcept; + Stream(const Stream&) = delete; + Stream& operator=(const Stream&) = delete; + ~Stream(); + + template + Stream& operator<<(T&& value) { + if (state && state->enabled) { + state->buffer << std::forward(value); + } + return *this; + } + + private: + struct State { + bool enabled; + bool emitted = false; + std::ostringstream buffer; + std::function emit; + }; + + explicit Stream(std::unique_ptr state); + void flush(); + + std::unique_ptr state; + + friend class Logger; + }; + + class Logger { + public: + Logger(const Logger&) noexcept = default; + Logger& operator=(const Logger&) noexcept = default; + Logger(Logger&&) noexcept = default; + Logger& operator=(Logger&&) noexcept = default; + ~Logger() = default; + + bool enabled(Level level) const noexcept; + void emit(Level level, Message message) const; + + Stream trace() const; + Stream debug() const; + Stream info() const; + Stream warn() const; + Stream error() const; + Stream critical() const; + Stream systemError(Level level, std::error_code error) const; + Stream systemError(Level level, int errorNumber) const; + + template + void trace(std::string_view pattern, Args&&... args) const { + if (enabled(Level::Trace)) { + write(Level::Trace, detail::format(pattern, std::forward(args)...)); + } + } + template + void debug(std::string_view pattern, Args&&... args) const { + if (enabled(Level::Debug)) { + write(Level::Debug, detail::format(pattern, std::forward(args)...)); + } + } + template + void info(std::string_view pattern, Args&&... args) const { + if (enabled(Level::Info)) { + write(Level::Info, detail::format(pattern, std::forward(args)...)); + } + } + template + void warn(std::string_view pattern, Args&&... args) const { + if (enabled(Level::Warning)) { + write(Level::Warning, detail::format(pattern, std::forward(args)...)); + } + } + template + void error(std::string_view pattern, Args&&... args) const { + if (enabled(Level::Error)) { + write(Level::Error, detail::format(pattern, std::forward(args)...)); + } + } + template + void critical(std::string_view pattern, Args&&... args) const { + if (enabled(Level::Critical)) { + write(Level::Critical, detail::format(pattern, std::forward(args)...)); + } + } + + template + void event(Level level, std::string eventName, std::string_view pattern, Args&&... args) const { + if (enabled(level)) { + writeEvent(level, std::move(eventName), detail::format(pattern, std::forward(args)...)); + } + } + + template + void systemError(Level level, std::error_code error, std::string_view pattern, Args&&... args) const { + if (enabled(level)) { + writeSystemError(level, std::move(error), detail::format(pattern, std::forward(args)...)); + } + } + + template + void systemError(Level level, int errorNumber, std::string_view pattern, Args&&... args) const { + systemError(level, + std::error_code(errorNumber, std::generic_category()), + pattern, + std::forward(args)...); + } + + private: + class Impl; + + explicit Logger(std::shared_ptr impl); + Stream stream(Level level) const; + void write(Level level, std::string message) const; + void writeEvent(Level level, std::string eventName, std::string message) const; + void writeSystemError(Level level, std::error_code error, std::string message) const; + + std::shared_ptr impl; + + friend Logger makeLogger(Scope scope); + }; + + Logger makeLogger(Scope scope); + Logger application(std::string component = "app", Identity identity = {}); + Logger framework(std::string component = "framework", Boundary boundary = Boundary::System, Identity identity = {}); + + template + Logger forConnection(const Connection& connection, + std::string component = "app", + Origin origin = Origin::Application, + Boundary boundary = Boundary::Connection, + std::optional role = std::nullopt) { + Identity identity; + if (!connection.getInstanceName().empty()) { + identity.instance = connection.getInstanceName(); + } + identity.role = role; + identity.connection = std::to_string(connection.getConnectionId()); + return makeLogger({origin, boundary, std::move(component), std::move(identity)}); + } + +} // namespace snode::log + +#endif // SNODEC_LOG_H diff --git a/src/apps/configtest.cpp b/src/apps/configtest.cpp index 580504edb..5749fa10a 100644 --- a/src/apps/configtest.cpp +++ b/src/apps/configtest.cpp @@ -39,8 +39,7 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -83,7 +82,7 @@ int main(int argc, char* argv[]) { CLI::Option* filenameOpt = subApp->add_option("-f", filename, "A Filename"); // filenameOpt->default_val("Filenameeeeee"); - snode::semantic::appLog().debug() << "Filename: " << filename; + snode::log::application().debug() << "Filename: " << filename; // app.needs(subApp); // subApp->needs(filenameOpt); diff --git a/src/apps/database/testmariadb.cpp b/src/apps/database/testmariadb.cpp index 905572a1b..085889e88 100644 --- a/src/apps/database/testmariadb.cpp +++ b/src/apps/database/testmariadb.cpp @@ -40,7 +40,7 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "core/timer/Timer.h" #include "database/mariadb/MariaDBClient.h" @@ -49,7 +49,6 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -112,11 +111,11 @@ int main(int argc, char* argv[]) { database::mariadb::MariaDBClient db1(details, [](const database::mariadb::MariaDBState& state) { if (state.error != 0) { - snode::semantic::appLog().error() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; + snode::log::application().error() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; } else if (state.connected) { - snode::semantic::mariaDbLog().info() << "MySQL connected"; + snode::log::framework("db.mariadb", snode::log::Boundary::Connection).info() << "MySQL connected"; } else { - snode::semantic::mariaDbLog().info() << "MySQL disconnected"; + snode::log::framework("db.mariadb", snode::log::Boundary::Connection).info() << "MySQL disconnected"; } }); @@ -125,68 +124,68 @@ int main(int argc, char* argv[]) { db1.exec( "DELETE FROM `snodec`", [&db1](void) -> void { - snode::semantic::appLog().debug() << "********** OnQuery 0;"; + snode::log::application().debug() << "********** OnQuery 0;"; db1.affectedRows( [](my_ulonglong affectedRows) -> void { - snode::semantic::appLog().debug() << "********** AffectedRows 1: " << affectedRows; + snode::log::application().debug() << "********** AffectedRows 1: " << affectedRows; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 1: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 1: " << errorString << " : " << errorNumber; }); }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "********** Error 0: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "********** Error 0: " << errorString << " : " << errorNumber; }) .exec( "INSERT INTO `snodec`(`username`, `password`) VALUES ('Annett','Hallo')", [&db1](void) -> void { - snode::semantic::appLog().debug() << "********** OnQuery 1: "; + snode::log::application().debug() << "********** OnQuery 1: "; db1.affectedRows( [](my_ulonglong affectedRows) -> void { - snode::semantic::appLog().debug() << "********** AffectedRows 2: " << affectedRows; + snode::log::application().debug() << "********** AffectedRows 2: " << affectedRows; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "********** Error 2: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "********** Error 2: " << errorString << " : " << errorNumber; }); }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "********** Error 1: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "********** Error 1: " << errorString << " : " << errorNumber; }) .query( "SELECT * FROM snodec", [&r](const MYSQL_ROW row) -> void { if (row != nullptr) { - snode::semantic::appLog().debug() << "********** Row Result 2: " << row[0] << " : " << row[1]; + snode::log::application().debug() << "********** Row Result 2: " << row[0] << " : " << row[1]; r++; } else { - snode::semantic::appLog().debug() << "********** Row Result 2: " << r; + snode::log::application().debug() << "********** Row Result 2: " << r; } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "********** Error 2: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "********** Error 2: " << errorString << " : " << errorNumber; }) .query( "SELECT * FROM snodec", [&r](const MYSQL_ROW row) -> void { if (row != nullptr) { - snode::semantic::appLog().debug() << "********** Row Result 2: " << row[0] << " : " << row[1]; + snode::log::application().debug() << "********** Row Result 2: " << row[0] << " : " << row[1]; r++; } else { - snode::semantic::appLog().debug() << "********** Row Result 2: " << r; + snode::log::application().debug() << "********** Row Result 2: " << r; } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "********** Error 2: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "********** Error 2: " << errorString << " : " << errorNumber; }); database::mariadb::MariaDBClient db2(details, [](const database::mariadb::MariaDBState& state) { if (state.error != 0) { - snode::semantic::appLog().error() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; + snode::log::application().error() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; } else if (state.connected) { - snode::semantic::mariaDbLog().info() << "MySQL connected"; + snode::log::framework("db.mariadb", snode::log::Boundary::Connection).info() << "MySQL connected"; } else { - snode::semantic::mariaDbLog().info() << "MySQL disconnected"; + snode::log::framework("db.mariadb", snode::log::Boundary::Connection).info() << "MySQL disconnected"; } }); @@ -197,49 +196,49 @@ int main(int argc, char* argv[]) { "SELECT * FROM snodec", [](const MYSQL_ROW row) -> void { if (row != nullptr) { - snode::semantic::appLog().debug() << "Row Result 3: " << row[0] << " : " << row[1]; + snode::log::application().debug() << "Row Result 3: " << row[0] << " : " << row[1]; } else { - snode::semantic::appLog().debug() << "Row Result 3:"; + snode::log::application().debug() << "Row Result 3:"; } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 3: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 3: " << errorString << " : " << errorNumber; }); db2.query( "SELECT * FROM snodec", [&db2, &r1, &r2](const MYSQL_ROW row) -> void { if (row != nullptr) { - snode::semantic::appLog().debug() << "Row Result 4: " << row[0] << " : " << row[1]; + snode::log::application().debug() << "Row Result 4: " << row[0] << " : " << row[1]; } else { - snode::semantic::appLog().debug() << "Row Result 4:"; + snode::log::application().debug() << "Row Result 4:"; db2.query( "SELECT * FROM snodec", [&db2, &r1, &r2](const MYSQL_ROW row) -> void { if (row != nullptr) { - snode::semantic::appLog().debug() << "Row Result 5: " << row[0] << " : " << row[1]; + snode::log::application().debug() << "Row Result 5: " << row[0] << " : " << row[1]; } else { // After all results have been fetched - snode::semantic::appLog().debug() << "Row Result 5:"; + snode::log::application().debug() << "Row Result 5:"; core::timer::Timer dbTimer1 = core::timer::Timer::intervalTimer( [&db2, &r1](const std::function& stop) -> void { static int i = 0; - snode::semantic::appLog().debug() << "Tick 2: " << i++; + snode::log::application().debug() << "Tick 2: " << i++; r1 = 0; db2.query( "SELECT * FROM snodec", [&r1](const MYSQL_ROW row) -> void { if (row != nullptr) { - snode::semantic::appLog().debug() << "Row Result 6: " << row[0] << " : " << row[1]; + snode::log::application().debug() << "Row Result 6: " << row[0] << " : " << row[1]; r1++; } else { - snode::semantic::appLog().debug() << "Row Result 6: " << r1; + snode::log::application().debug() << "Row Result 6: " << r1; } }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 6: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 6: " << errorString << " : " << errorNumber; stop(); }); }, @@ -248,150 +247,150 @@ 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; - snode::semantic::appLog().debug() << "Tick 0.7: " << i++; + snode::log::application().debug() << "Tick 0.7: " << i++; r2 = 0; db2.query( "SELECT * FROM snodec", [&db2, &r2](const MYSQL_ROW row) -> void { if (row != nullptr) { - snode::semantic::appLog().debug() << "Row Result 7: " << row[0] << " : " << row[1]; + snode::log::application().debug() << "Row Result 7: " << row[0] << " : " << row[1]; r2++; } else { - snode::semantic::appLog().debug() << "Row Result 7: " << r2; + snode::log::application().debug() << "Row Result 7: " << r2; db2.fieldCount( [](unsigned int fieldCount) -> void { - snode::semantic::appLog().debug() + snode::log::application().debug() << "************ FieldCount ************ = " << fieldCount; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() + snode::log::application().debug() << "Error 7: " << errorString << " : " << errorNumber; }); } }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 7: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 7: " << errorString << " : " << errorNumber; stop(); }) .fieldCount( [](unsigned int fieldCount) -> void { - snode::semantic::appLog().debug() + snode::log::application().debug() << "************ FieldCount ************ = " << fieldCount; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 7: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 7: " << errorString << " : " << errorNumber; }); }, 0.7); } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 5: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 5: " << errorString << " : " << errorNumber; }); } }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 4: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 4: " << errorString << " : " << errorNumber; }); core::timer::Timer dbTimer = core::timer::Timer::intervalTimer( [&db2](const std::function& stop) -> void { static int i = 0; - snode::semantic::appLog().debug() << "Tick 0.1: " << i++; + snode::log::application().debug() << "Tick 0.1: " << i++; if (i >= 60000) { - snode::semantic::appLog().debug() << "Stop Stop"; + snode::log::application().debug() << "Stop Stop"; stop(); } int j = i; db2.startTransactions( [](void) -> void { - snode::semantic::appLog().debug() << "Transactions activated 10:"; + snode::log::application().debug() << "Transactions activated 10:"; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 8: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 8: " << errorString << " : " << errorNumber; }) .exec( "INSERT INTO `snodec`(`username`, `password`) VALUES ('Annett','Hallo')", [&db2, j](void) -> void { - snode::semantic::appLog().debug() << "Inserted 10: " << j; + snode::log::application().debug() << "Inserted 10: " << j; db2.affectedRows( [](my_ulonglong affectedRows) -> void { - snode::semantic::appLog().debug() << "AffectedRows 11: " << affectedRows; + snode::log::application().debug() << "AffectedRows 11: " << affectedRows; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 11: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 11: " << errorString << " : " << errorNumber; }); }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 10: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 10: " << errorString << " : " << errorNumber; stop(); }) .rollback( [](void) -> void { - snode::semantic::appLog().debug() << "Rollback success 11"; + snode::log::application().debug() << "Rollback success 11"; }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 12: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 12: " << errorString << " : " << errorNumber; stop(); }) .exec( "INSERT INTO `snodec`(`username`, `password`) VALUES ('Annett','Hallo')", [&db2, j](void) -> void { - snode::semantic::appLog().debug() << "Inserted 13: " << j; + snode::log::application().debug() << "Inserted 13: " << j; db2.affectedRows( [](my_ulonglong affectedRows) -> void { - snode::semantic::appLog().debug() << "AffectedRows 14: " << affectedRows; + snode::log::application().debug() << "AffectedRows 14: " << affectedRows; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 14: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 14: " << errorString << " : " << errorNumber; }); }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 13: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 13: " << errorString << " : " << errorNumber; stop(); }) .commit( [](void) -> void { - snode::semantic::appLog().debug() << "Commit success 15"; + snode::log::application().debug() << "Commit success 15"; }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 15: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 15: " << errorString << " : " << errorNumber; stop(); }) .query( "SELECT COUNT(*) FROM snodec", [&db2, j, stop](const MYSQL_ROW row) -> void { if (row != nullptr) { - snode::semantic::appLog().debug() << "Row Result count(*) 16: " << row[0]; + snode::log::application().debug() << "Row Result count(*) 16: " << row[0]; if (std::atoi(row[0]) != j + 1) { // NOLINT - snode::semantic::appLog().debug() + snode::log::application().debug() << "Wrong number of rows 16: " << std::atoi(row[0]) << " != " << j + 1; // NOLINT // exit(1); } } else { - snode::semantic::appLog().debug() << "Row Result count(*) 16: no result:"; + snode::log::application().debug() << "Row Result count(*) 16: no result:"; db2.fieldCount( [](unsigned int fieldCount) -> void { - snode::semantic::appLog().debug() << "************ FieldCount ************ = " << fieldCount; + snode::log::application().debug() << "************ FieldCount ************ = " << fieldCount; }, [](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 7: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 7: " << errorString << " : " << errorNumber; }); } }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 16: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 16: " << errorString << " : " << errorNumber; stop(); }) .endTransactions( [](void) -> void { - snode::semantic::appLog().debug() << "Transactions deactivated 17"; + snode::log::application().debug() << "Transactions deactivated 17"; }, [stop](const std::string& errorString, unsigned int errorNumber) -> void { - snode::semantic::appLog().debug() << "Error 17: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Error 17: " << errorString << " : " << errorNumber; stop(); }); }, diff --git a/src/apps/echo/echoclient.cpp b/src/apps/echo/echoclient.cpp index 10badcaa5..773aaf876 100644 --- a/src/apps/echo/echoclient.cpp +++ b/src/apps/echo/echoclient.cpp @@ -39,13 +39,12 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "model/clients.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #endif /* DOXYGEN_SHOULD_SKIP_THIS */ @@ -60,16 +59,16 @@ int main(int argc, char* argv[]) { [instanceName = client.getConfig()->getInstanceName()](const SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -77,16 +76,16 @@ int main(int argc, char* argv[]) { client.connect([](const SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "echoclient: connected to '" << socketAddress.toString() << "'" << "'"; + snode::log::application().info() << "echoclient: connected to '" << socketAddress.toString() << "'" << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "echoclient: disabled"; + snode::log::application().info() << "echoclient: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "echoclientt: error occurred"; + snode::log::application().warn() << "echoclientt: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "echoclient: fatal error occurred"; + snode::log::application().error() << "echoclient: fatal error occurred"; break; } }); @@ -122,11 +121,11 @@ int main(int argc, char* argv[]) { #endif if (errnum < 0) { - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError"; + snode::log::application().systemError(snode::log::Level::Error, errnum) << "OnError"; } else if (errnum > 0) { - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "OnError: " << socketAddress.toString(); + snode::log::application().systemError(snode::log::Level::Error, errnum) << "OnError: " << socketAddress.toString(); } else { - snode::semantic::appLog().debug() << "snode.c connecting to " << socketAddress.toString(); + snode::log::application().debug() << "snode.c connecting to " << socketAddress.toString(); } #ifdef NET_TYPE diff --git a/src/apps/echo/echoserver.cpp b/src/apps/echo/echoserver.cpp index 0230641a6..4bf7ab102 100644 --- a/src/apps/echo/echoserver.cpp +++ b/src/apps/echo/echoserver.cpp @@ -39,13 +39,12 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "model/servers.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #if (STREAM_TYPE == TLS) @@ -84,16 +83,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -128,9 +127,9 @@ int main(int argc, char* argv[]) { server.listen("/tmp/testme", 5, [](const SocketServer::Socket& socket, int errnum) { // titan #endif if (errnum != 0) { - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Critical, errnum) << "listen"; + snode::log::application().systemError(snode::log::Level::Critical, errnum) << "listen"; } else { - snode::semantic::appLog().info() << "snode.c listening on " << socket.getBindAddress().toString(); + snode::log::application().info() << "snode.c listening on " << socket.getBindAddress().toString(); } #ifdef NET_TYPE diff --git a/src/apps/echo/model/clients.h b/src/apps/echo/model/clients.h index 61a8d8b38..e08d0431a 100644 --- a/src/apps/echo/model/clients.h +++ b/src/apps/echo/model/clients.h @@ -42,8 +42,7 @@ #ifndef APPS_ECHO_MODEL_CLIENT_H #define APPS_ECHO_MODEL_CLIENT_H -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #define QUOTE_INCLUDE(a) STR(a) #define STR(a) #a @@ -91,10 +90,10 @@ namespace apps::echo::model::tls { EchoSocketClient client("echoclient"); client.setOnConnect([&client](SocketConnection* socketConnection) { // onConnect - snode::semantic::appLog().debug() << "OnConnect " << client.getConfig()->getInstanceName(); + snode::log::application().debug() << "OnConnect " << client.getConfig()->getInstanceName(); - snode::semantic::appLog().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); - snode::semantic::appLog().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -107,26 +106,26 @@ namespace apps::echo::model::tls { }); client.setOnConnected([&client](SocketConnection* socketConnection) { // onConnected - snode::semantic::appLog().debug() << "OnConnected " << client.getConfig()->getInstanceName(); + snode::log::application().debug() << "OnConnected " << client.getConfig()->getInstanceName(); - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Debug)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Debug)) { X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { const long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - snode::semantic::appLog().debug() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + + snode::log::application().debug() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << "\t Subject: " << str; + snode::log::application().debug() << "\t Subject: " << str; OPENSSL_free(str); } str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << "\t Issuer: " << str; + snode::log::application().debug() << "\t Issuer: " << str; OPENSSL_free(str); } @@ -137,21 +136,21 @@ namespace apps::echo::model::tls { const int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - snode::semantic::appLog().debug() << "\t Subject alternative name count: " << altNameCount; + snode::log::application().debug() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - snode::semantic::appLog().debug() << "\t SAN (URI): '" + subjectAltName; + snode::log::application().debug() << "\t SAN (URI): '" + subjectAltName; } else if (generalName->type == GEN_DNS) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.dNSName)), static_cast(ASN1_STRING_length(generalName->d.dNSName))); - snode::semantic::appLog().debug() << "\t SAN (DNS): '" + subjectAltName; + snode::log::application().debug() << "\t SAN (DNS): '" + subjectAltName; } else { - snode::semantic::appLog().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::log::application().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -159,16 +158,16 @@ namespace apps::echo::model::tls { X509_free(server_cert); } else { - snode::semantic::appLog().debug() << "\tPeer certificate: no certificate"; + snode::log::application().debug() << "\tPeer certificate: no certificate"; } } }); client.setOnDisconnect([&client](SocketConnection* socketConnection) { // onDisconnect - snode::semantic::appLog().debug() << "OnDisconnect " << client.getConfig()->getInstanceName(); + snode::log::application().debug() << "OnDisconnect " << client.getConfig()->getInstanceName(); - snode::semantic::appLog().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); - snode::semantic::appLog().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); return client; diff --git a/src/apps/echo/model/servers.h b/src/apps/echo/model/servers.h index 8a650c741..083f8b592 100644 --- a/src/apps/echo/model/servers.h +++ b/src/apps/echo/model/servers.h @@ -42,8 +42,7 @@ #ifndef APPS_ECHO_MODEL_SERVER_H #define APPS_ECHO_MODEL_SERVER_H -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #define QUOTE_INCLUDE(a) STR_INCLUDE(a) #define STR_INCLUDE(a) #a @@ -91,10 +90,10 @@ namespace apps::echo::model::tls { EchoSocketServer server("echoserver"); server.setOnConnect([&server](SocketConnection* socketConnection) { // onConnect - snode::semantic::appLog().debug() << "OnConnect " << server.getConfig()->getInstanceName(); + snode::log::application().debug() << "OnConnect " << server.getConfig()->getInstanceName(); - snode::semantic::appLog().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); - snode::semantic::appLog().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -107,26 +106,26 @@ namespace apps::echo::model::tls { }); server.setOnConnected([&server](SocketConnection* socketConnection) { // onConnected - snode::semantic::appLog().debug() << "OnConnected " << server.getConfig()->getInstanceName(); + snode::log::application().debug() << "OnConnected " << server.getConfig()->getInstanceName(); - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Debug)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Debug)) { X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - snode::semantic::appLog().debug() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + + snode::log::application().debug() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << "\t Subject: " << str; + snode::log::application().debug() << "\t Subject: " << str; OPENSSL_free(str); } str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << "\t Issuer: " << str; + snode::log::application().debug() << "\t Issuer: " << str; OPENSSL_free(str); } @@ -137,21 +136,21 @@ namespace apps::echo::model::tls { int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - snode::semantic::appLog().debug() << "\t Subject alternative name count: " << altNameCount; + snode::log::application().debug() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - snode::semantic::appLog().debug() << "\t SAN (URI): '" + subjectAltName; + snode::log::application().debug() << "\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))); - snode::semantic::appLog().debug() << "\t SAN (DNS): '" + subjectAltName; + snode::log::application().debug() << "\t SAN (DNS): '" + subjectAltName; } else { - snode::semantic::appLog().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::log::application().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -159,16 +158,16 @@ namespace apps::echo::model::tls { X509_free(server_cert); } else { - snode::semantic::appLog().debug() << "\tPeer certificate: no certificate"; + snode::log::application().debug() << "\tPeer certificate: no certificate"; } } }); server.setOnDisconnect([&server](SocketConnection* socketConnection) { // onDisconnect - snode::semantic::appLog().debug() << "OnDisconnect " << server.getConfig()->getInstanceName(); + snode::log::application().debug() << "OnDisconnect " << server.getConfig()->getInstanceName(); - snode::semantic::appLog().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); - snode::semantic::appLog().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); return server; diff --git a/src/apps/express_compat_server.cpp b/src/apps/express_compat_server.cpp index 640d92508..aa9f24de7 100644 --- a/src/apps/express_compat_server.cpp +++ b/src/apps/express_compat_server.cpp @@ -3,10 +3,9 @@ * * Intended to be used alongside the Node.js/Express reference server in this suite. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "express/legacy/in/WebApp.h" -#include "log/Logger.h" #include @@ -238,16 +237,16 @@ int main(int argc, char* argv[]) { app.listen(8080, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "express-compat listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << "express-compat listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "express-compat disabled"; + snode::log::application().info() << "express-compat disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << "express-compat " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << "express-compat " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << "express-compat " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << "express-compat " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/http/httpclient.cpp b/src/apps/http/httpclient.cpp index 202e30b87..2564d3d59 100644 --- a/src/apps/http/httpclient.cpp +++ b/src/apps/http/httpclient.cpp @@ -39,13 +39,12 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "apps/http/model/clients.h" #include "core/SNodeC.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #endif /* DOXYGEN_SHOULD_SKIP_THIS */ @@ -61,16 +60,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/http/httplowlevelclient.cpp b/src/apps/http/httplowlevelclient.cpp index 7000e85d3..aaf887ca3 100644 --- a/src/apps/http/httplowlevelclient.cpp +++ b/src/apps/http/httplowlevelclient.cpp @@ -39,7 +39,7 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "core/socket/stream/SocketContext.h" #include "core/socket/stream/SocketContextFactory.h" @@ -49,7 +49,6 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -70,13 +69,13 @@ namespace apps::http { web::http::client::ResponseParser* responseParser = new web::http::client::ResponseParser( socketContext, []() { - snode::semantic::appLog().debug() << "++ OnStarted"; + snode::log::application().debug() << "++ OnStarted"; }, []([[maybe_unused]] web::http::client::Response& res) { - snode::semantic::appLog().debug() << "++ OnParsed"; + snode::log::application().debug() << "++ OnParsed"; }, [](int status, const std::string& reason) { - snode::semantic::appLog().debug() << "++ OnError: " + std::to_string(status) + " - " + reason; + snode::log::application().debug() << "++ OnError: " + std::to_string(status) + " - " + reason; }); return responseParser; @@ -92,10 +91,10 @@ namespace apps::http { ~SimpleSocketProtocol() override; void onConnected() override { - snode::semantic::appLog().debug() << "SimpleSocketProtocol connected"; + snode::log::application().debug() << "SimpleSocketProtocol connected"; } void onDisconnected() override { - snode::semantic::appLog().debug() << "SimpleSocketProtocol disconnected"; + snode::log::application().debug() << "SimpleSocketProtocol disconnected"; } bool onSignal([[maybe_unused]] int signum) override { @@ -149,10 +148,10 @@ namespace tls { SocketClient tlsClient( "tls", [](SocketConnection* socketConnection) { // onConnect - snode::semantic::appLog().debug() << "OnConnect"; + snode::log::application().debug() << "OnConnect"; - snode::semantic::appLog().debug() << "\tServer: " << socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " << socketConnection->getLocalAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -164,26 +163,26 @@ namespace tls { // } }, [](SocketConnection* socketConnection) { // onConnected - snode::semantic::appLog().debug() << "OnConnected"; + snode::log::application().debug() << "OnConnected"; - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Debug)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Debug)) { X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { const long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - snode::semantic::appLog().debug() + snode::log::application().debug() << " Server certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << " Subject: " << str; + snode::log::application().debug() << " Subject: " << str; OPENSSL_free(str); } str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << " Issuer: " << str; + snode::log::application().debug() << " Issuer: " << str; OPENSSL_free(str); } @@ -194,21 +193,21 @@ namespace tls { const int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - snode::semantic::appLog().debug() << "\t Subject alternative name count: " << altNameCount; + snode::log::application().debug() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { const std::string subjectAltName = std::string( reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - snode::semantic::appLog().debug() << "\t SAN (URI): '" + subjectAltName; + snode::log::application().debug() << "\t SAN (URI): '" + subjectAltName; } else if (generalName->type == GEN_DNS) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.dNSName)), static_cast(ASN1_STRING_length(generalName->d.dNSName))); - snode::semantic::appLog().debug() << "\t SAN (DNS): '" + subjectAltName; + snode::log::application().debug() << "\t SAN (DNS): '" + subjectAltName; } else { - snode::semantic::appLog().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::log::application().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -216,17 +215,17 @@ namespace tls { X509_free(server_cert); } else { - snode::semantic::appLog().debug() << " Server certificate: no certificate"; + snode::log::application().debug() << " Server certificate: no certificate"; } } socketConnection->sendToPeer("GET /index.html HTTP/1.1\r\nConnection: close\r\n\r\n"); // Connection: close\r\n\r\n"); }, [](SocketConnection* socketConnection) { // onDisconnect - snode::semantic::appLog().debug() << "OnDisconnect"; + snode::log::application().debug() << "OnDisconnect"; - snode::semantic::appLog().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); @@ -239,16 +238,16 @@ namespace tls { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -267,29 +266,29 @@ namespace legacy { SocketClient legacyClient( "legacy", [](SocketConnection* socketConnection) { // OnConnect - snode::semantic::appLog().debug() << "OnConnect"; + snode::log::application().debug() << "OnConnect"; - snode::semantic::appLog().debug() << "\tServer: " << socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " << socketConnection->getLocalAddress().toString(); }, [](SocketConnection* socketConnection) { // onConnected - snode::semantic::appLog().debug() << "OnConnected"; + snode::log::application().debug() << "OnConnected"; socketConnection->sendToPeer("GET /index.html HTTP/1.1\r\nConnection: close\r\n\r\n"); // Connection: close\r\n\r\n"); }, [](SocketConnection* socketConnection) { // onDisconnect - snode::semantic::appLog().debug() << "OnDisconnect"; + snode::log::application().debug() << "OnDisconnect"; - snode::semantic::appLog().debug() << "\tServer: " << socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " << socketConnection->getLocalAddress().toString(); }); SocketAddress remoteAddress("localhost", 8080); remoteAddress.init(); - snode::semantic::appLog().debug() << "###############': " << remoteAddress.getCanonName(); - snode::semantic::appLog().debug() << "###############': " << remoteAddress.toString(); + snode::log::application().debug() << "###############': " << remoteAddress.getCanonName(); + snode::log::application().debug() << "###############': " << remoteAddress.toString(); legacyClient.connect( remoteAddress, @@ -298,16 +297,16 @@ namespace legacy { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -332,16 +331,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -357,16 +356,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { // example.com:81 simulate connnect timeout switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/http/httpserver.cpp b/src/apps/http/httpserver.cpp index e434c07e7..49b0956e5 100644 --- a/src/apps/http/httpserver.cpp +++ b/src/apps/http/httpserver.cpp @@ -40,7 +40,7 @@ */ #include "ConfigWWW.h" -#include "SemanticLog.h" +#include "Log.h" #include "apps/http/model/servers.h" #include "express/middleware/StaticMiddleware.h" @@ -53,7 +53,6 @@ #endif // (STREAM_TYPE == TLS) -#include "log/Logger.h" #include #include @@ -86,8 +85,8 @@ int main(int argc, char* argv[]) { webApp.getConfig()->addSniCerts(sniCerts); #endif - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Routes:"; for (std::string route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); @@ -100,16 +99,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/http/model/clients.h b/src/apps/http/model/clients.h index e4f393034..1212b1d50 100644 --- a/src/apps/http/model/clients.h +++ b/src/apps/http/model/clients.h @@ -52,14 +52,12 @@ // clang-format on -#include "SemanticLog.h" +#include "Log.h" #include CLIENT_INCLUDE // IWYU pragma: export #include EVENTSOURCE_INCLUDE // IWYU pragma: export #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" -#include "log/SemanticLogger.h" #include "web/http/http_utils.h" #if (STREAM_TYPE == TLS) // tls @@ -71,8 +69,8 @@ #endif /* DOXYGEN_SHOULD_SKIP_THIS */ static void logResponse(const std::shared_ptr& req, const std::shared_ptr& res) { - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { const std::string prefix = req->getConnectionName() + " HTTP response: " + req->method + " " + req->url + " HTTP/" + std::to_string(req->httpMajor) + "." + std::to_string(req->httpMinor) + "\n"; const auto requestPresentation = @@ -86,8 +84,8 @@ static void logResponse(const std::shared_ptr& req, {}); const auto responsePresentation = httputils::toStringPresentation(res->httpVersion, res->statusCode, res->reason, res->headers, res->cookies, res->body); - log.emit(logger::LogLevel::Trace, - logger::PresentedMessage{.plain = prefix + requestPresentation.plain + "\n" + responsePresentation.plain, + log.emit(snode::log::Level::Trace, + snode::log::Message{.plain = prefix + requestPresentation.plain + "\n" + responsePresentation.plain, .terminal = prefix + requestPresentation.terminal + "\n" + responsePresentation.terminal}); } } @@ -106,7 +104,7 @@ namespace apps::http::legacy { Client client( "httpclient", [](const std::shared_ptr& req) { - snode::semantic::appLog().debug() + snode::log::application().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestStart"; req->httpMajor = 1; @@ -131,15 +129,15 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.tt", [req](int ret) { if (ret == 0) { - snode::semantic::appLog().debug() + snode::log::application().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::appLog().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.tt"; + snode::log::application().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.tt"; } else { - snode::semantic::appLog().error() + snode::log::application().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, ret) + snode::log::application().systemError(snode::log::Level::Error, ret) << " /home/voc/projects/snodec/snode.c/CMakeLists.tt"; } }, @@ -309,25 +307,25 @@ namespace apps::http::legacy { if (eventStream_1) { eventStream_1->onOpen([]() { - snode::semantic::appLog().debug() << "OnOpen 1"; + snode::log::application().debug() << "OnOpen 1"; }); eventStream_1->onError([]() { - snode::semantic::appLog().debug() << "OnError 1"; + snode::log::application().debug() << "OnError 1"; }); eventStream_1->onMessage([](const web::http::client::tools::EventSource::MessageEvent& message) { - snode::semantic::appLog().debug() << "OnMessage 1:1: " << message.data; + snode::log::application().debug() << "OnMessage 1:1: " << message.data; }); eventStream_1->onMessage([](const web::http::client::tools::EventSource::MessageEvent& message) { - snode::semantic::appLog().debug() << "OnMessage 1:2: " << message.data; + snode::log::application().debug() << "OnMessage 1:2: " << message.data; }); eventStream_1->addEventListener("myevent", [](const web::http::client::tools::EventSource::MessageEvent& message) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "EventListener for 'myevent' 1:1: " << message.lastEventId << " : " << message.data; }); eventStream_1->addEventListener("myevent", [](const web::http::client::tools::EventSource::MessageEvent& message) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "EventListener for 'myevent' 1:2: " << message.lastEventId << " : " << message.data; }); @@ -342,25 +340,25 @@ namespace apps::http::legacy { if (eventStream_2) { eventStream_2->onOpen([]() { - snode::semantic::appLog().debug() << "OnOpen 2"; + snode::log::application().debug() << "OnOpen 2"; }); eventStream_2->onError([]() { - snode::semantic::appLog().debug() << "OnError 2"; + snode::log::application().debug() << "OnError 2"; }); eventStream_2->onMessage([](const web::http::client::tools::EventSource::MessageEvent& message) { - snode::semantic::appLog().debug() << "OnMessage 2:1: " << message.data; + snode::log::application().debug() << "OnMessage 2:1: " << message.data; }); eventStream_2->onMessage([](const web::http::client::tools::EventSource::MessageEvent& message) { - snode::semantic::appLog().debug() << "OnMessage 2:2: " << message.data; + snode::log::application().debug() << "OnMessage 2:2: " << message.data; }); eventStream_2->addEventListener("myevent", [](const web::http::client::tools::EventSource::MessageEvent& message) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "EventListener for 'myevent' 2:1: " << message.lastEventId << " : " << message.data; }); eventStream_2->addEventListener("myevent", [](const web::http::client::tools::EventSource::MessageEvent& message) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "EventListener for 'myevent' 2:2: " << message.lastEventId << " : " << message.data; }); } @@ -384,13 +382,13 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.txt", [req](int ret) { if (ret == 0) { - snode::semantic::appLog().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::log::application().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::appLog().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::log::application().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } else { - snode::semantic::appLog().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::log::application().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, ret) + snode::log::application().systemError(snode::log::Level::Error, ret) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } }, @@ -405,13 +403,13 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.txt", [&req](int ret) { if (ret == 0) { - snode::semantic::appLog().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::log::application().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::appLog().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::log::application().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } else { - snode::semantic::appLog().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::log::application().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, ret) + snode::log::application().systemError(snode::log::Level::Error, ret) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } }, @@ -442,13 +440,13 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.txt", [req](int ret) { if (ret == 0) { - snode::semantic::appLog().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::log::application().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::appLog().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::log::application().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } else { - snode::semantic::appLog().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::log::application().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, ret) + snode::log::application().systemError(snode::log::Level::Error, ret) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } }, @@ -468,13 +466,13 @@ namespace apps::http::legacy { "/home/voc/projects/snodec/snode.c/CMakeLists.txt", [req](int ret) { if (ret == 0) { - snode::semantic::appLog().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::log::application().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request accepted: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::appLog().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; + snode::log::application().debug() << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } else { - snode::semantic::appLog().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() + snode::log::application().error() << req->getSocketContext()->getSocketConnection()->getConnectionName() << " HTTP: Request failed: GET / HTTP/" << req->httpMajor << "." << req->httpMinor; - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, ret) + snode::log::application().systemError(snode::log::Level::Error, ret) << " /home/voc/projects/snodec/snode.c/CMakeLists.txt"; } }, @@ -488,21 +486,21 @@ namespace apps::http::legacy { #endif }, []([[maybe_unused]] const std::shared_ptr& req) { - snode::semantic::appLog().debug() << req->getConnectionName() << ": OnRequestEnd"; + snode::log::application().debug() << req->getConnectionName() << ": OnRequestEnd"; }); client.setOnConnect([](SocketConnection* socketConnection) { // onConnect - snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnConnect"; + snode::log::application().debug() << socketConnection->getConnectionName() << ": OnConnect"; - snode::semantic::appLog().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); - snode::semantic::appLog().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); client.setOnDisconnect([](SocketConnection* socketConnection) { // onDisconnect - snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnDisconnect"; + snode::log::application().debug() << socketConnection->getConnectionName() << ": OnDisconnect"; - snode::semantic::appLog().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); - snode::semantic::appLog().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); return client; @@ -526,7 +524,7 @@ namespace apps::http::tls { Client client( "httpclient", [](const std::shared_ptr& req) { - snode::semantic::appLog().debug() + snode::log::application().debug() << req->getSocketContext()->getSocketConnection()->getConnectionName() << ": OnRequestStart"; req->url = "/"; @@ -675,14 +673,14 @@ namespace apps::http::tls { }); }, []([[maybe_unused]] const std::shared_ptr& req) { - snode::semantic::appLog().debug() << req->getConnectionName() << ": OnRequestEnd"; + snode::log::application().debug() << req->getConnectionName() << ": OnRequestEnd"; }); client.setOnConnect([](SocketConnection* socketConnection) { // onConnect - snode::semantic::appLog().debug() << "OnConnect " << socketConnection->getConnectionName(); + snode::log::application().debug() << "OnConnect " << socketConnection->getConnectionName(); - snode::semantic::appLog().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); - snode::semantic::appLog().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -695,25 +693,25 @@ namespace apps::http::tls { }); client.setOnConnected([](SocketConnection* socketConnection) { // onConnected - snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnConnected"; - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Debug)) { + snode::log::application().debug() << socketConnection->getConnectionName() << ": OnConnected"; + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Debug)) { X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert != nullptr) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - snode::semantic::appLog().debug() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + + snode::log::application().debug() << "\tPeer certificate verifyErr = " + std::to_string(verifyErr) + ": " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(server_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << "\t Subject: " << str; + snode::log::application().debug() << "\t Subject: " << str; OPENSSL_free(str); } str = X509_NAME_oneline(X509_get_issuer_name(server_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << "\t Issuer: " << str; + snode::log::application().debug() << "\t Issuer: " << str; OPENSSL_free(str); } @@ -724,21 +722,21 @@ namespace apps::http::tls { int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - snode::semantic::appLog().debug() << "\t Subject alternative name count: " << altNameCount; + snode::log::application().debug() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - snode::semantic::appLog().debug() << "\t SAN (URI): '" + subjectAltName; + snode::log::application().debug() << "\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))); - snode::semantic::appLog().debug() << "\t SAN (DNS): '" + subjectAltName; + snode::log::application().debug() << "\t SAN (DNS): '" + subjectAltName; } else { - snode::semantic::appLog().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::log::application().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -746,16 +744,16 @@ namespace apps::http::tls { X509_free(server_cert); } else { - snode::semantic::appLog().debug() << "\tPeer certificate: no certificate"; + snode::log::application().debug() << "\tPeer certificate: no certificate"; } } }); client.setOnDisconnect([](SocketConnection* socketConnection) { // onDisconnect - snode::semantic::appLog().debug() << socketConnection->getConnectionName() << ": OnDisconnect"; + snode::log::application().debug() << socketConnection->getConnectionName() << ": OnDisconnect"; - snode::semantic::appLog().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); - snode::semantic::appLog().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tLocal: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tPeer: " << socketConnection->getRemoteAddress().toString(); }); return client; diff --git a/src/apps/http/model/servers.h b/src/apps/http/model/servers.h index a0e5b9c92..82dfb7d91 100644 --- a/src/apps/http/model/servers.h +++ b/src/apps/http/model/servers.h @@ -49,14 +49,13 @@ #define WEBAPP_INCLUDE QUOTE_INCLUDE(express/STREAM/NET/WebApp.h) // clang-format on -#include "SemanticLog.h" +#include "Log.h" #include WEBAPP_INCLUDE // IWYU pragma: export #include "express/middleware/VerboseRequest.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #if (STREAM_TYPE == TLS) // tls #include @@ -100,10 +99,10 @@ namespace apps::http::tls { const std::string& instanceName = webApp.getConfig()->getInstanceName(); webApp.setOnConnect([instanceName](SocketConnection* socketConnection) { // onConnect - snode::semantic::appLog().debug() << "OnConnect " << instanceName; + snode::log::application().debug() << "OnConnect " << instanceName; - snode::semantic::appLog().debug() << " Local: " << socketConnection->getLocalAddress().toString(); - snode::semantic::appLog().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << " Local: " << socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(); /* Enable automatic hostname checks */ // X509_VERIFY_PARAM* param = SSL_get0_param(socketConnection->getSSL()); @@ -116,14 +115,14 @@ namespace apps::http::tls { }); webApp.setOnConnected([instanceName](SocketConnection* socketConnection) { // onConnected - snode::semantic::appLog().debug() << "OnConnected " << instanceName; + snode::log::application().debug() << "OnConnected " << instanceName; - auto log = snode::semantic::appLog(); + auto log = snode::log::application(); X509* server_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (server_cert == nullptr) { log.warn() << "\tPeer certificate: no certificate"; } else { - if (log.enabled(logger::LogLevel::Debug)) { + if (log.enabled(snode::log::Level::Debug)) { long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); log.debug() << "\tPeer certificate verifyErr = " << verifyErr << ": " << X509_verify_cert_error_string(verifyErr); @@ -174,21 +173,21 @@ namespace apps::http::tls { }); webApp.setOnDisconnect([instanceName](SocketConnection* socketConnection) { // onDisconnect - snode::semantic::appLog().debug() << "OnDisconnect " << instanceName; + snode::log::application().debug() << "OnDisconnect " << instanceName; - snode::semantic::appLog().debug() << " Local: " << socketConnection->getLocalAddress().toString(false); - snode::semantic::appLog().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(false); + snode::log::application().debug() << " Local: " << socketConnection->getLocalAddress().toString(false); + snode::log::application().debug() << " Peer: " << socketConnection->getRemoteAddress().toString(false); - snode::semantic::appLog().debug() << " Online Since: " << socketConnection->getOnlineSince(); - snode::semantic::appLog().debug() << " Online Duration: " << socketConnection->getOnlineDuration(); + snode::log::application().debug() << " Online Since: " << socketConnection->getOnlineSince(); + snode::log::application().debug() << " Online Duration: " << socketConnection->getOnlineDuration(); - snode::semantic::appLog().debug() << " Total Queued: " << socketConnection->getTotalQueued(); - snode::semantic::appLog().debug() << " Total Sent: " << socketConnection->getTotalSent(); - snode::semantic::appLog().debug() << " Write Delta: " + snode::log::application().debug() << " Total Queued: " << socketConnection->getTotalQueued(); + snode::log::application().debug() << " Total Sent: " << socketConnection->getTotalSent(); + snode::log::application().debug() << " Write Delta: " << socketConnection->getTotalQueued() - socketConnection->getTotalSent(); - snode::semantic::appLog().debug() << " Total Read: " << socketConnection->getTotalRead(); - snode::semantic::appLog().debug() << " Total Processed: " << socketConnection->getTotalProcessed(); - snode::semantic::appLog().debug() << " Read Delta: " + snode::log::application().debug() << " Total Read: " << socketConnection->getTotalRead(); + snode::log::application().debug() << " Total Processed: " << socketConnection->getTotalProcessed(); + snode::log::application().debug() << " Read Delta: " << socketConnection->getTotalRead() - socketConnection->getTotalProcessed(); }); diff --git a/src/apps/http/testbasicauthentication.cpp b/src/apps/http/testbasicauthentication.cpp index ba91c1570..5c0808867 100644 --- a/src/apps/http/testbasicauthentication.cpp +++ b/src/apps/http/testbasicauthentication.cpp @@ -40,7 +40,7 @@ */ #include "ConfigWWW.h" -#include "SemanticLog.h" +#include "Log.h" #include "express/legacy/in6/WebApp.h" #include "express/middleware/BasicAuthentication.h" #include "express/middleware/StaticMiddleware.h" @@ -50,7 +50,6 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #endif /* DOXYGEN_SHOULD_SKIP_THIS */ @@ -99,16 +98,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -135,17 +134,17 @@ int main(int argc, char* argv[]) { tlsServer.listen(8088, [](const legacy::in6::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "tls: listening on '" << socketAddress.toString() << "'" + snode::log::application().info() << "tls: listening on '" << socketAddress.toString() << "'" << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "tls: disabled"; + snode::log::application().info() << "tls: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "tls: error occurred"; + snode::log::application().warn() << "tls: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "tls: fatal error occurred"; + snode::log::application().error() << "tls: fatal error occurred"; break; } }); diff --git a/src/apps/http/testexpressnext.cpp b/src/apps/http/testexpressnext.cpp index 656763e45..257c2c5d0 100644 --- a/src/apps/http/testexpressnext.cpp +++ b/src/apps/http/testexpressnext.cpp @@ -39,11 +39,10 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "core/timer/Timer.h" #include "express/legacy/in/WebApp.h" -#include "log/Logger.h" #include "web/http/legacy/in/Client.h" #include @@ -100,7 +99,7 @@ class NextTester { [this](const Client::SocketAddress&, const core::socket::State& state) { if (state != core::socket::State::OK) { ++failures; - snode::semantic::appLog().error() << "FAIL: connect failed: " << state.what(); + snode::log::application().error() << "FAIL: connect failed: " << state.what(); core::timer::Timer::singleshotTimer( [] { core::SNodeC::stop(); @@ -122,7 +121,7 @@ class NextTester { void dispatchNextRequest() { if (testCases.empty()) { - snode::semantic::appLog().info() << "All express next() tests executed. failures=" << failures; + snode::log::application().info() << "All express next() tests executed. failures=" << failures; if (masterRequest && masterRequest->isConnected()) { masterRequest->disconnect(); } @@ -136,7 +135,7 @@ class NextTester { if (!masterRequest || !masterRequest->isConnected()) { ++failures; - snode::semantic::appLog().error() << "FAIL: master request not connected"; + snode::log::application().error() << "FAIL: master request not connected"; core::timer::Timer::singleshotTimer( [] { core::SNodeC::stop(); @@ -159,11 +158,11 @@ class NextTester { const bool bodyOk = body.find(current.expectedBody) != std::string::npos; if (statusOk && bodyOk) { - snode::semantic::appLog().info() + snode::log::application().info() << "PASS: " << current.name << " status=" << res->statusCode << " body='" << body << "'"; } else { ++failures; - snode::semantic::appLog().error() << "FAIL: " << current.name << " expected status=" << current.expectedStatus + snode::log::application().error() << "FAIL: " << current.name << " expected status=" << current.expectedStatus << " expected body fragment='" << current.expectedBody << "'" << " got status=" << res->statusCode << " body='" << body << "'"; } @@ -172,7 +171,7 @@ class NextTester { }, [this, current]([[maybe_unused]] const std::shared_ptr& req, const std::string& reason) { ++failures; - snode::semantic::appLog().error() << "FAIL: " << current.name << " parse-error: " << reason; + snode::log::application().error() << "FAIL: " << current.name << " parse-error: " << reason; dispatchNextRequest(); }); } @@ -303,16 +302,16 @@ int main(int argc, char* argv[]) { app.listen(18080, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "testexpressnext listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << "testexpressnext listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "testexpressnext disabled"; + snode::log::application().info() << "testexpressnext disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << "testexpressnext " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << "testexpressnext " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << "testexpressnext " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << "testexpressnext " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -326,10 +325,10 @@ int main(int argc, char* argv[]) { const int rc = core::SNodeC::start(); if (nextTester.getFailures() > 0) { - snode::semantic::appLog().error() << "testexpressnext finished with failures=" << nextTester.getFailures(); + snode::log::application().error() << "testexpressnext finished with failures=" << nextTester.getFailures(); return 1; } - snode::semantic::appLog().info() << "testexpressnext finished successfully"; + snode::log::application().info() << "testexpressnext finished successfully"; return rc; } diff --git a/src/apps/http/verysimpleserver.cpp b/src/apps/http/verysimpleserver.cpp index 89846579b..4c9c9c38c 100644 --- a/src/apps/http/verysimpleserver.cpp +++ b/src/apps/http/verysimpleserver.cpp @@ -40,7 +40,7 @@ */ #include "ConfigWWW.h" -#include "SemanticLog.h" +#include "Log.h" #include "express/legacy/in/WebApp.h" #include "express/middleware/StaticMiddleware.h" #include "express/tls/in/WebApp.h" @@ -48,7 +48,6 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #endif /* DOXYGEN_SHOULD_SKIP_THIS */ @@ -70,17 +69,17 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << " disabled"; + snode::log::application().info() << instanceName << " disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() + snode::log::application().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() + snode::log::application().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } @@ -104,16 +103,16 @@ int main(int argc, char* argv[]) { [instanceName = legacyApp.getConfig()->getInstanceName()](const TLSSocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << " disabled"; + snode::log::application().info() << instanceName << " disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/http/vhostserver.cpp b/src/apps/http/vhostserver.cpp index 3604221bb..947707204 100644 --- a/src/apps/http/vhostserver.cpp +++ b/src/apps/http/vhostserver.cpp @@ -40,7 +40,7 @@ */ #include "ConfigWWW.h" -#include "SemanticLog.h" +#include "Log.h" #include "express/legacy/in6/WebApp.h" #include "express/middleware/StaticMiddleware.h" #include "express/middleware/VHost.h" @@ -48,7 +48,6 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include "utils/Config.h" #endif /* DOXYGEN_SHOULD_SKIP_THIS */ @@ -123,16 +122,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << " disabled"; + snode::log::application().info() << instanceName << " disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -192,17 +191,17 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << " disabled"; + snode::log::application().info() << instanceName << " disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() + snode::log::application().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() + snode::log::application().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } diff --git a/src/apps/jsonclient.cpp b/src/apps/jsonclient.cpp index fd45bcf83..01d08778e 100644 --- a/src/apps/jsonclient.cpp +++ b/src/apps/jsonclient.cpp @@ -39,13 +39,12 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "web/http/legacy/in/Client.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #endif /* DOXYGEN_SHOULD_SKIP_THIS */ @@ -61,7 +60,7 @@ int main(int argc, char* argv[]) { const Client jsonClient( "legacy", [](const std::shared_ptr& req) { - snode::semantic::appLog().debug() << "-- OnRequest"; + snode::log::application().debug() << "-- OnRequest"; req->method = "POST"; req->url = "/index.html"; req->type("application/json"); @@ -69,38 +68,38 @@ int main(int argc, char* argv[]) { req->send( R"({"userId":1,"schnitzel":"good","hungry":false})", []([[maybe_unused]] const std::shared_ptr& req, const std::shared_ptr& res) { - snode::semantic::appLog().debug() << "-- OnResponse"; - snode::semantic::appLog().debug() << " Status:"; - snode::semantic::appLog().debug() << " " << res->httpVersion; - snode::semantic::appLog().debug() << " " << res->statusCode; - snode::semantic::appLog().debug() << " " << res->reason; + snode::log::application().debug() << "-- OnResponse"; + snode::log::application().debug() << " Status:"; + snode::log::application().debug() << " " << res->httpVersion; + snode::log::application().debug() << " " << res->statusCode; + snode::log::application().debug() << " " << res->reason; - snode::semantic::appLog().debug() << " Headers:"; + snode::log::application().debug() << " Headers:"; for (const auto& [field, value] : res->headers) { - snode::semantic::appLog().debug() << " " << field + " = " + value; + snode::log::application().debug() << " " << field + " = " + value; } - snode::semantic::appLog().debug() << " Cookies:"; + snode::log::application().debug() << " Cookies:"; for (const auto& [name, cookie] : res->cookies) { - snode::semantic::appLog().debug() << " " + name + " = " + cookie.getValue(); + snode::log::application().debug() << " " + name + " = " + cookie.getValue(); for (const auto& [option, value] : cookie.getOptions()) { - snode::semantic::appLog().debug() << " " + option + " = " + value; + snode::log::application().debug() << " " + option + " = " + value; } } - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Debug)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Debug)) { res->body.push_back(0); log.debug() << " Body:\n----------- start body -----------" << res->body.data() << "------------ end body ------------"; } }, [](const std::shared_ptr&, const std::string& message) { - snode::semantic::appLog().debug() << "legacy: Request parse error: " << message; + snode::log::application().debug() << "legacy: Request parse error: " << message; }); }, []([[maybe_unused]] const std::shared_ptr& req) { - snode::semantic::appLog().info() << " -- OnRequestEnd"; + snode::log::application().info() << " -- OnRequestEnd"; }); jsonClient.connect( @@ -111,23 +110,23 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { // example.com:81 simulate connect timeout switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); /* jsonClient.post("localhost", 8080, "/index.html", "{\"userId\":1,\"schnitzel\":\"good\",\"hungry\":false}", [](int err) { if (err != 0) { - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, err) << "OnError: " << err; + snode::log::application().systemError(snode::log::Level::Error, err) << "OnError: " << err; } }); */ diff --git a/src/apps/jsonserver.cpp b/src/apps/jsonserver.cpp index 421be5eb2..b1b7dc876 100644 --- a/src/apps/jsonserver.cpp +++ b/src/apps/jsonserver.cpp @@ -39,13 +39,12 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "express/legacy/in/WebApp.h" #include "express/middleware/JsonMiddleware.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include @@ -69,16 +68,16 @@ int main(int argc, char* argv[]) { [instanceName = legacyApp.getConfig()->getInstanceName()](const SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } }); @@ -89,13 +88,13 @@ int main(int argc, char* argv[]) { req->getAttribute( [&jsonString](nlohmann::json& json) { jsonString = json.dump(4); - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Debug)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Debug)) { log.debug() << "Application received body: " << jsonString; } }, [](const std::string& key) { - snode::semantic::appLog().debug() << key << " attribute not found"; + snode::log::application().debug() << key << " attribute not found"; }); res->send(jsonString); diff --git a/src/apps/main.cpp b/src/apps/main.cpp index 3ec4a24df..88d4760c2 100644 --- a/src/apps/main.cpp +++ b/src/apps/main.cpp @@ -39,12 +39,11 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "core/timer/Timer.h" #include "express/legacy/in/WebApp.h" #include "express/middleware/VerboseRequest.h" -#include "log/Logger.h" #include #include @@ -237,16 +236,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << " disabled"; + snode::log::application().info() << instanceName << " disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); diff --git a/src/apps/oauth2/authorization_server/AuthorizationServer.cpp b/src/apps/oauth2/authorization_server/AuthorizationServer.cpp index 24b2b818a..db8fe9244 100644 --- a/src/apps/oauth2/authorization_server/AuthorizationServer.cpp +++ b/src/apps/oauth2/authorization_server/AuthorizationServer.cpp @@ -39,12 +39,11 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "database/mariadb/MariaDBClient.h" #include "express/legacy/in/WebApp.h" #include "express/middleware/JsonMiddleware.h" #include "express/middleware/StaticMiddleware.h" -#include "log/Logger.h" #include "utils/sha1.h" #include @@ -105,12 +104,12 @@ int main(int argc, char* argv[]) { }; database::mariadb::MariaDBClient db{details, [](const database::mariadb::MariaDBState& state) { if (state.error != 0) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; } else if (state.connected) { - snode::semantic::mariaDbLog().info() << "MySQL connected"; + snode::log::framework("db.mariadb", snode::log::Boundary::Connection).info() << "MySQL connected"; } else { - snode::semantic::mariaDbLog().info() << "MySQL disconnected"; + snode::log::framework("db.mariadb", snode::log::Boundary::Connection).info() << "MySQL disconnected"; } }}; @@ -127,17 +126,17 @@ int main(int argc, char* argv[]) { [req, res, next, queryClientId](const MYSQL_ROW row) { if (row != nullptr) { if (std::stoi(row[0]) > 0) { - snode::semantic::appLog().debug() << "Valid client id '" << queryClientId << "'"; - snode::semantic::appLog().debug() << "Next with " << req->httpVersion << " " << req->method << " " << req->url; + snode::log::application().debug() << "Valid client id '" << queryClientId << "'"; + snode::log::application().debug() << "Next with " << req->httpVersion << " " << req->method << " " << req->url; next(); } else { - snode::semantic::appLog().debug() << "Invalid client id '" << queryClientId << "'"; + snode::log::application().debug() << "Invalid client id '" << queryClientId << "'"; res->sendStatus(401); } } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } else { @@ -155,14 +154,14 @@ int main(int argc, char* argv[]) { const std::string paramScope{req->query("scope")}; const std::string paramState{req->query("state")}; - snode::semantic::appLog().debug() << "Query params: " + snode::log::application().debug() << "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") { - snode::semantic::appLog().debug() << "Auth invalid, sending Bad Request"; + snode::log::application().debug() << "Auth invalid, sending Bad Request"; res->sendStatus(400); return; } @@ -171,10 +170,10 @@ int main(int argc, char* argv[]) { db.exec( "update client set redirect_uri = '" + paramRedirectUri + "' where uuid = '" + paramClientId + "'", [paramRedirectUri]() { - snode::semantic::appLog().debug() << "Database: Set redirect_uri to " << paramRedirectUri; + snode::log::application().debug() << "Database: Set redirect_uri to " << paramRedirectUri; }, [](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; }); } @@ -182,10 +181,10 @@ int main(int argc, char* argv[]) { db.exec( "update client set scope = '" + paramScope + "' where uuid = '" + paramClientId + "'", [paramScope]() { - snode::semantic::appLog().debug() << "Database: Set scope to " << paramScope; + snode::log::application().debug() << "Database: Set scope to " << paramScope; }, [](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; }); } @@ -193,14 +192,14 @@ int main(int argc, char* argv[]) { db.exec( "update client set state = '" + paramState + "' where uuid = '" + paramClientId + "'", [paramState]() { - snode::semantic::appLog().debug() << "Database: Set state to " << paramState; + snode::log::application().debug() << "Database: Set state to " << paramState; }, [](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; }); } - snode::semantic::appLog().debug() << "Auth request valid, redirecting to login"; + snode::log::application().debug() << "Auth request valid, redirecting to login"; std::string loginUri{"/oauth2/login"}; addQueryParamToUri(loginUri, "client_id", paramClientId); res->redirect(loginUri); @@ -210,7 +209,7 @@ int main(int argc, char* argv[]) { res->sendFile("/home/rathalin/projects/snode.c/src/oauth2/authorization_server/vue-frontend-oauth2-auth-server/dist/index.html", [req](int ret) { if (ret != 0) { - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, ret) << req->url; + snode::log::application().systemError(snode::log::Level::Error, ret) << req->url; } }); }); @@ -249,7 +248,7 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) .query( @@ -274,25 +273,25 @@ int main(int argc, char* argv[]) { res->set("Access-Control-Allow-Origin", "*"); const nlohmann::json responseJson = {{"redirect_uri", clientRedirectUri}}; const std::string responseJsonString{responseJson.dump(4)}; - snode::semantic::appLog().debug() << "Sending json reponse: " << responseJsonString; + snode::log::application().debug() << "Sending json reponse: " << responseJsonString; res->send(responseJsonString); }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); }, @@ -304,11 +303,11 @@ int main(int argc, char* argv[]) { router.get("/token", [&db] APPLICATION(req, res) { res->set("Access-Control-Allow-Origin", "*"); auto queryGrantType = req->query("grant_type"); - snode::semantic::appLog().debug() << "GrandType: " << queryGrantType; + snode::log::application().debug() << "GrandType: " << queryGrantType; auto queryCode = req->query("code"); - snode::semantic::appLog().debug() << "Code: " << queryCode; + snode::log::application().debug() << "Code: " << queryCode; auto queryRedirectUri = req->query("redirect_uri"); - snode::semantic::appLog().debug() << "RedirectUri: " << queryRedirectUri; + snode::log::application().debug() << "RedirectUri: " << queryRedirectUri; if (queryGrantType != "authorization_code") { res->status(400).send("Invalid query parameter 'grant_type', value must be 'authorization_code'"); return; @@ -367,7 +366,7 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) @@ -385,14 +384,14 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) @@ -406,7 +405,7 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) @@ -430,28 +429,28 @@ int main(int argc, char* argv[]) { res->send(jsonResponseString); }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); }); @@ -459,14 +458,14 @@ 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"); - snode::semantic::appLog().debug() << "ClientId: " << queryClientId; + snode::log::application().debug() << "ClientId: " << queryClientId; auto queryGrantType = req->query("grant_type"); - snode::semantic::appLog().debug() << "GrandType: " << queryGrantType; + snode::log::application().debug() << "GrandType: " << queryGrantType; auto queryRefreshToken = req->query("refresh_token"); - snode::semantic::appLog().debug() << "RefreshToken supplied: " << !queryRefreshToken.empty() + snode::log::application().debug() << "RefreshToken supplied: " << !queryRefreshToken.empty() << " (length=" << queryRefreshToken.size() << ")"; auto queryState = req->query("state"); - snode::semantic::appLog().debug() << "State: " << queryState; + snode::log::application().debug() << "State: " << queryState; if (queryGrantType.length() == 0) { res->status(400).send("Missing query parameter 'grant_type'"); return; @@ -507,7 +506,7 @@ int main(int argc, char* argv[]) { []() { }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }) .query( @@ -527,34 +526,34 @@ int main(int argc, char* argv[]) { res->send(responseJson.dump(4)); }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); }); router.post("/token/validate", [&db] APPLICATION(req, res) { - snode::semantic::appLog().debug() << "POST /token/validate"; + snode::log::application().debug() << "POST /token/validate"; req->getAttribute([res, &db](nlohmann::json& jsonBody) { if (!jsonBody.contains("access_token")) { - snode::semantic::appLog().debug() << "Missing 'access_token' in json"; + snode::log::application().debug() << "Missing 'access_token' in json"; res->status(500).send("Missing 'access_token' in json"); return; } const std::string jsonAccessToken{jsonBody["access_token"]}; if (!jsonBody.contains("client_id")) { - snode::semantic::appLog().debug() << "Missing 'client_id' in json"; + snode::log::application().debug() << "Missing 'client_id' in json"; res->status(500).send("Missing 'client_id' in json"); return; } @@ -573,17 +572,17 @@ int main(int argc, char* argv[]) { if (row != nullptr) { if (std::stoi(row[0]) == 0) { const nlohmann::json errorJson = {{"error", "Invalid access token"}}; - snode::semantic::appLog().debug() << "Sending 401: Invalid access token"; + snode::log::application().debug() << "Sending 401: Invalid access token"; res->status(401).send(errorJson.dump(4)); } else { - snode::semantic::appLog().debug() << "Sending 200: Valid access token"; + snode::log::application().debug() << "Sending 200: Valid access token"; const nlohmann::json successJson = {{"success", "Valid access token"}}; res->status(200).send(successJson.dump(4)); } } }, [res](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().debug() << "Database error: " << errorString << " : " << errorNumber; + snode::log::application().debug() << "Database error: " << errorString << " : " << errorNumber; res->sendStatus(500); }); }); @@ -596,16 +595,16 @@ int main(int argc, char* argv[]) { app.listen(8082, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "OAuth2AuthorizationServer: listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << "OAuth2AuthorizationServer: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "OAuth2AuthorizationServer: disabled"; + snode::log::application().info() << "OAuth2AuthorizationServer: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "OAuth2AuthorizationServer: error occurred"; + snode::log::application().warn() << "OAuth2AuthorizationServer: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "OAuth2AuthorizationServer: fatal error occurred"; + snode::log::application().error() << "OAuth2AuthorizationServer: fatal error occurred"; break; } }); diff --git a/src/apps/oauth2/client_app/ClientApp.cpp b/src/apps/oauth2/client_app/ClientApp.cpp index 28ddd6b68..2cd0e4902 100644 --- a/src/apps/oauth2/client_app/ClientApp.cpp +++ b/src/apps/oauth2/client_app/ClientApp.cpp @@ -39,10 +39,9 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "express/legacy/in/WebApp.h" #include "express/middleware/StaticMiddleware.h" -#include "log/Logger.h" int main(int argc, char* argv[]) { express::WebApp::init(argc, argv); @@ -54,7 +53,7 @@ int main(int argc, char* argv[]) { res->sendFile("/home/rathalin/projects/snode.c/src/oauth2/client_app/vue-frontend-oauth2-client/dist/index.html", [req](int ret) { if (ret != 0) { - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, ret) << req->url; + snode::log::application().systemError(snode::log::Level::Error, ret) << req->url; } }); } @@ -65,16 +64,16 @@ int main(int argc, char* argv[]) { app.listen(8081, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "OAuth2Client: connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << "OAuth2Client: connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "OAuth2Client: disabled"; + snode::log::application().info() << "OAuth2Client: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "OAuth2Client: error occurred"; + snode::log::application().warn() << "OAuth2Client: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "OAuth2Client: fatal error occurred"; + snode::log::application().error() << "OAuth2Client: fatal error occurred"; break; } }); diff --git a/src/apps/oauth2/resource_server/ResourceServer.cpp b/src/apps/oauth2/resource_server/ResourceServer.cpp index 9e2dfe646..48ff8d4cc 100644 --- a/src/apps/oauth2/resource_server/ResourceServer.cpp +++ b/src/apps/oauth2/resource_server/ResourceServer.cpp @@ -39,10 +39,9 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "express/legacy/in/WebApp.h" #include "express/middleware/JsonMiddleware.h" -#include "log/Logger.h" #include "web/http/legacy/in/Client.h" #include @@ -64,33 +63,33 @@ int main(int argc, char* argv[]) { const std::string queryAccessToken{req->query("access_token")}; const std::string queryClientId{req->query("client_id")}; if (queryAccessToken.empty() || queryClientId.empty()) { - snode::semantic::appLog().warn() << "Missing access_token or client_id in body"; + snode::log::application().warn() << "Missing access_token or client_id in body"; res->sendStatus(401); return; } const web::http::legacy::in::Client legacyClient( [](web::http::legacy::in::Client::SocketConnection* socketConnection) { - snode::semantic::appLog().debug() << "OnConnect"; + snode::log::application().debug() << "OnConnect"; - snode::semantic::appLog().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); }, []([[maybe_unused]] web::http::legacy::in::Client::SocketConnection* socketConnection) { - snode::semantic::appLog().debug() << "OnConnected"; + snode::log::application().debug() << "OnConnected"; }, [](web::http::legacy::in::Client::SocketConnection* socketConnection) { - snode::semantic::appLog().debug() << "OnDisconnect"; + snode::log::application().debug() << "OnDisconnect"; - snode::semantic::appLog().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); }, [queryAccessToken, queryClientId, res](const std::shared_ptr& request) { - snode::semantic::appLog().debug() << "OnRequestBegin"; + snode::log::application().debug() << "OnRequestBegin"; request->url = "/oauth2/token/validate?client_id=" + queryClientId; request->method = "POST"; - snode::semantic::appLog().debug() << "ClientId: " << queryClientId; - snode::semantic::appLog().debug() + snode::log::application().debug() << "ClientId: " << queryClientId; + snode::log::application().debug() << "AccessToken supplied: " << !queryAccessToken.empty() << " (length=" << queryAccessToken.size() << ")"; const nlohmann::json requestJson = {{"access_token", queryAccessToken}, {"client_id", queryClientId}}; const std::string requestJsonString{requestJson.dump(4)}; @@ -98,8 +97,8 @@ int main(int argc, char* argv[]) { requestJsonString, [res]([[maybe_unused]] const std::shared_ptr& request, const std::shared_ptr& response) { - snode::semantic::appLog().debug() << "OnResponse"; - snode::semantic::appLog().debug() << "Response: " << std::string(response->body.begin(), response->body.end()); + snode::log::application().debug() << "OnResponse"; + snode::log::application().debug() << "Response: " << std::string(response->body.begin(), response->body.end()); if (std::stoi(response->statusCode) != 200) { const nlohmann::json errorJson = {{"error", "Invalid access token"}}; res->status(401).send(errorJson.dump(4)); @@ -109,27 +108,27 @@ int main(int argc, char* argv[]) { } }, [](const std::shared_ptr&, const std::string& message) { - snode::semantic::appLog().debug() << "OAuth2ResourceServer: Request parse error: " << message; + snode::log::application().debug() << "OAuth2ResourceServer: Request parse error: " << message; }); }, []([[maybe_unused]] const std::shared_ptr& req) { - snode::semantic::appLog().info() << " -- OnRequestEnd"; + snode::log::application().info() << " -- OnRequestEnd"; }); legacyClient.connect( "localhost", 8082, [](const web::http::legacy::in::Client::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "OAuth2ResourceServer: connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << "OAuth2ResourceServer: connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "OAuth2ResourceServer: disabled"; + snode::log::application().info() << "OAuth2ResourceServer: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "OAuth2ResourceServer: error occurred"; + snode::log::application().warn() << "OAuth2ResourceServer: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "OAuth2ResourceServer: fatal error occurred"; + snode::log::application().error() << "OAuth2ResourceServer: fatal error occurred"; break; } }); @@ -138,16 +137,16 @@ int main(int argc, char* argv[]) { app.listen(8083, [](const express::legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "app: listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << "app: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "app: disabled"; + snode::log::application().info() << "app: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "app: error occurred"; + snode::log::application().warn() << "app: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "app: fatal error occurred"; + snode::log::application().error() << "app: fatal error occurred"; break; } }); diff --git a/src/apps/testpipe.cpp b/src/apps/testpipe.cpp index cb40ca4af..30f9993cf 100644 --- a/src/apps/testpipe.cpp +++ b/src/apps/testpipe.cpp @@ -39,7 +39,7 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "core/pipe/Pipe.h" #include "core/pipe/PipeSink.h" @@ -47,7 +47,6 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -62,28 +61,28 @@ int main(int argc, char* argv[]) { []([[maybe_unused]] core::pipe::PipeSource& pipeSource, [[maybe_unused]] core::pipe::PipeSink& pipeSink) { pipeSink.setOnData([&pipeSource](const char* chunk, std::size_t chunkLen) { const std::string string(chunk, chunkLen); - snode::semantic::appLog().debug() << "Pipe Data: " << string; + snode::log::application().debug() << "Pipe Data: " << string; pipeSource.send(chunk, chunkLen); // pipeSink.disable(); // pipeSource.disable(); }); pipeSink.setOnEof([]() { - snode::semantic::appLog().debug() << "Pipe EOF"; + snode::log::application().debug() << "Pipe EOF"; }); pipeSink.setOnError([]([[maybe_unused]] int errnum) { - snode::semantic::appLog().debug() << "PipeSink"; + snode::log::application().debug() << "PipeSink"; }); pipeSource.setOnError([]([[maybe_unused]] int errnum) { - snode::semantic::appLog().debug() << "PipeSource"; + snode::log::application().debug() << "PipeSource"; }); pipeSource.send("Hello World!"); }, []([[maybe_unused]] int errnum) { - snode::semantic::sysError(snode::semantic::appLog(), logger::LogLevel::Error, errnum) << "Pipe not created"; + snode::log::application().systemError(snode::log::Level::Error, errnum) << "Pipe not created"; }); return core::SNodeC::start(); diff --git a/src/apps/testpost.cpp b/src/apps/testpost.cpp index 89f7451ec..2f14cb649 100644 --- a/src/apps/testpost.cpp +++ b/src/apps/testpost.cpp @@ -39,14 +39,13 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "express/legacy/in/WebApp.h" #include "express/middleware/VerboseRequest.h" #include "express/tls/in/WebApp.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #endif /* DOXYGEN_SHOULD_SKIP_THIS */ @@ -108,16 +107,16 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const LegacySocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "legacyApp: listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << "legacyApp: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "legacyApp: disabled"; + snode::log::application().info() << "legacyApp: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "legacyApp: error occurred"; + snode::log::application().warn() << "legacyApp: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "legacyApp: fatal error occurred"; + snode::log::application().error() << "legacyApp: fatal error occurred"; break; } }); @@ -138,16 +137,16 @@ int main(int argc, char* argv[]) { tlsApp.listen("localhost", 8088, [](const TLSSocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "tlsApp: listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << "tlsApp: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "tlsApp: disabled"; + snode::log::application().info() << "tlsApp: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "tlsApp: error occurred"; + snode::log::application().warn() << "tlsApp: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "tlsApp: fatal error occurred"; + snode::log::application().error() << "tlsApp: fatal error occurred"; break; } }); diff --git a/src/apps/testregex.cpp b/src/apps/testregex.cpp index bad055baf..822147f18 100644 --- a/src/apps/testregex.cpp +++ b/src/apps/testregex.cpp @@ -39,14 +39,13 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "database/mariadb/MariaDBClient.h" #include "express/legacy/in/WebApp.h" #include "express/tls/in/WebApp.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -105,11 +104,11 @@ Router router(database::mariadb::MariaDBClient& db) { .get( "/query/:userId", [] MIDDLEWARE(req, res, next) { - snode::semantic::appLog().debug() << "Move on to the next route to query database"; + snode::log::application().debug() << "Move on to the next route to query database"; next(); }, [&db] MIDDLEWARE(req, res, next) { // http://localhost:8080/query/123 - snode::semantic::appLog().debug() << "UserId: " << req->params["userId"]; + snode::log::application().debug() << "UserId: " << req->params["userId"]; std::string userId = req->params["userId"]; req->setAttribute(std::string()); @@ -160,29 +159,29 @@ Router router(database::mariadb::MariaDBClient& db) { " \n" "\n")); }); - snode::semantic::appLog().debug() << "Move on to the next route to send result"; + snode::log::application().debug() << "Move on to the next route to send result"; next(); } }, [res, userId](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().warn() << "Error: " << errorString << " : " << errorNumber; + snode::log::application().warn() << "Error: " << errorString << " : " << errorNumber; res->status(404).send(userId + ": " + errorString + " - " + std::to_string(errorNumber)); }); }, [] MIDDLEWARE(req, res, next) { - snode::semantic::appLog().debug() << "And again 1: Move on to the next route to send result"; + snode::log::application().debug() << "And again 1: Move on to the next route to send result"; next(); }, [] MIDDLEWARE(req, res, next) { - snode::semantic::appLog().debug() << "And again 2: Move on to the next route to send result"; + snode::log::application().debug() << "And again 2: Move on to the next route to send result"; next(); }) .get([] MIDDLEWARE(req, res, next) { - snode::semantic::appLog().debug() << "And again 3: Move on to the next route to send result"; + snode::log::application().debug() << "And again 3: Move on to the next route to send result"; next(); }) .get([] APPLICATION(req, res) { - snode::semantic::appLog().debug() << "SendResult"; + snode::log::application().debug() << "SendResult"; req->getAttribute( [res](std::string& table) { @@ -193,9 +192,9 @@ Router router(database::mariadb::MariaDBClient& db) { }); }); router.get("/account/:userId(\\d*)/:userName", [&db] APPLICATION(req, res) { // http://localhost:8080/account/123/perfectNDSgroup - snode::semantic::appLog().debug() << "Show account of"; - snode::semantic::appLog().debug() << "UserId: " << req->params["userId"]; - snode::semantic::appLog().debug() << "UserName: " << req->params["userName"]; + snode::log::application().debug() << "Show account of"; + snode::log::application().debug() << "UserId: " << req->params["userId"]; + snode::log::application().debug() << "UserName: " << req->params["userName"]; const std::string response = "" " " @@ -220,18 +219,18 @@ Router router(database::mariadb::MariaDBClient& db) { db.exec( "INSERT INTO `snodec`(`username`, `password`) VALUES ('" + userId + "','" + userName + "')", [userId, userName]() { - snode::semantic::appLog().debug() << "Inserted: -> " << userId << " - " << userName; + snode::log::application().debug() << "Inserted: -> " << userId << " - " << userName; }, [](const std::string& errorString, unsigned int errorNumber) { - snode::semantic::appLog().warn() << "Error: " << errorString << " : " << errorNumber; + snode::log::application().warn() << "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 - snode::semantic::appLog().debug() << "Testing Regex"; - snode::semantic::appLog().debug() << "Regex1: " << req->params["testRegex1"]; - snode::semantic::appLog().debug() << "Regex2: " << req->params["testRegex2"]; + snode::log::application().debug() << "Testing Regex"; + snode::log::application().debug() << "Regex1: " << req->params["testRegex1"]; + snode::log::application().debug() << "Regex2: " << req->params["testRegex2"]; const std::string response = "" " " @@ -253,9 +252,9 @@ Router router(database::mariadb::MariaDBClient& db) { res->send(response); }); router.get("/search/:search", [] APPLICATION(req, res) { // http://localhost:8080/search/buxtehude123 - snode::semantic::appLog().debug() << "Show Search of"; - snode::semantic::appLog().debug() << "Search: " << req->params["search"]; - snode::semantic::appLog().debug() << "Queries: " << req->query("test"); + snode::log::application().debug() << "Show Search of"; + snode::log::application().debug() << "Search: " << req->params["search"]; + snode::log::application().debug() << "Queries: " << req->query("test"); res->send(req->params["search"]); }); @@ -288,11 +287,11 @@ int main(int argc, char* argv[]) { database::mariadb::MariaDBClient db(details, [](const database::mariadb::MariaDBState& state) { if (state.error != 0) { - snode::semantic::appLog().error() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; + snode::log::application().error() << "MySQL error: " << state.errorMessage << " [" << state.error << "]"; } else if (state.connected) { - snode::semantic::mariaDbLog().info() << "MySQL connected"; + snode::log::framework("db.mariadb", snode::log::Boundary::Connection).info() << "MySQL connected"; } else { - snode::semantic::mariaDbLog().info() << "MySQL disconnected"; + snode::log::framework("db.mariadb", snode::log::Boundary::Connection).info() << "MySQL disconnected"; } }); @@ -304,32 +303,32 @@ int main(int argc, char* argv[]) { legacyApp.listen(8080, [](const legacy::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "legacy-testregex: listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << "legacy-testregex: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "legacy-testregex: disabled"; + snode::log::application().info() << "legacy-testregex: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "legacy-testregex: error occurred"; + snode::log::application().warn() << "legacy-testregex: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "legacy-testregex: fatal error occurred"; + snode::log::application().error() << "legacy-testregex: fatal error occurred"; break; } }); legacyApp.setOnConnect([](legacy::in::WebApp::SocketConnection* socketConnection) { - snode::semantic::appLog().debug() << "OnConnect:"; + snode::log::application().debug() << "OnConnect:"; - snode::semantic::appLog().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); legacyApp.setOnDisconnect([](legacy::in::WebApp::SocketConnection* socketConnection) { - snode::semantic::appLog().debug() << "OnDisconnect:"; + snode::log::application().debug() << "OnDisconnect:"; - snode::semantic::appLog().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); tls::in::WebApp tlsApp("tls-testregex"); @@ -339,48 +338,48 @@ int main(int argc, char* argv[]) { tlsApp.listen(8088, [](const tls::in::WebApp::SocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << "tls-testregex: listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << "tls-testregex: listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << "tls-testregex: disabled"; + snode::log::application().info() << "tls-testregex: disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().warn() << "tls-testregex: error occurred"; + snode::log::application().warn() << "tls-testregex: error occurred"; break; case core::socket::State::FATAL: - snode::semantic::appLog().error() << "tls-testregex: fatal error occurred"; + snode::log::application().error() << "tls-testregex: fatal error occurred"; break; } }); tlsApp.setOnConnect([](tls::in::WebApp::SocketConnection* socketConnection) { - snode::semantic::appLog().debug() << "OnConnect:"; + snode::log::application().debug() << "OnConnect:"; - snode::semantic::appLog().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); tlsApp.setOnConnected([](tls::in::WebApp::SocketConnection* socketConnection) { - snode::semantic::appLog().debug() << "OnConnected:"; + snode::log::application().debug() << "OnConnected:"; - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Debug)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Debug)) { X509* client_cert = SSL_get_peer_certificate(socketConnection->getSSL()); if (client_cert != nullptr) { const long verifyErr = SSL_get_verify_result(socketConnection->getSSL()); - snode::semantic::appLog().debug() << "\tClient certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); + snode::log::application().debug() << "\tClient certificate: " + std::string(X509_verify_cert_error_string(verifyErr)); char* str = X509_NAME_oneline(X509_get_subject_name(client_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << "\t Subject: " << str; + snode::log::application().debug() << "\t Subject: " << str; OPENSSL_free(str); } str = X509_NAME_oneline(X509_get_issuer_name(client_cert), nullptr, 0); if (str != nullptr) { - snode::semantic::appLog().debug() << "\t Issuer: " << str; + snode::log::application().debug() << "\t Issuer: " << str; OPENSSL_free(str); } @@ -391,21 +390,21 @@ int main(int argc, char* argv[]) { const int32_t altNameCount = sk_GENERAL_NAME_num(subjectAltNames); - snode::semantic::appLog().debug() << "\t Subject alternative name count: " << altNameCount; + snode::log::application().debug() << "\t Subject alternative name count: " << altNameCount; for (int32_t i = 0; i < altNameCount; ++i) { GENERAL_NAME* generalName = sk_GENERAL_NAME_value(subjectAltNames, i); if (generalName->type == GEN_URI) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.uniformResourceIdentifier)), static_cast(ASN1_STRING_length(generalName->d.uniformResourceIdentifier))); - snode::semantic::appLog().debug() << "\t SAN (URI): '" + subjectAltName; + snode::log::application().debug() << "\t SAN (URI): '" + subjectAltName; } else if (generalName->type == GEN_DNS) { const std::string subjectAltName = std::string(reinterpret_cast(ASN1_STRING_get0_data(generalName->d.dNSName)), static_cast(ASN1_STRING_length(generalName->d.dNSName))); - snode::semantic::appLog().debug() << "\t SAN (DNS): '" + subjectAltName; + snode::log::application().debug() << "\t SAN (DNS): '" + subjectAltName; } else { - snode::semantic::appLog().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); + snode::log::application().debug() << "\t SAN (Type): '" + std::to_string(generalName->type); } } @@ -413,16 +412,16 @@ int main(int argc, char* argv[]) { X509_free(client_cert); } else { - snode::semantic::appLog().debug() << "\tClient certificate: no certificate"; + snode::log::application().debug() << "\tClient certificate: no certificate"; } } }); tlsApp.setOnDisconnect([](tls::in::WebApp::SocketConnection* socketConnection) { - snode::semantic::appLog().debug() << "OnDisconnect:"; + snode::log::application().debug() << "OnDisconnect:"; - snode::semantic::appLog().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); - snode::semantic::appLog().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); + snode::log::application().debug() << "\tServer: " + socketConnection->getRemoteAddress().toString(); + snode::log::application().debug() << "\tClient: " + socketConnection->getLocalAddress().toString(); }); } diff --git a/src/apps/tlslegacy/TlsLegacySocketContext.cpp b/src/apps/tlslegacy/TlsLegacySocketContext.cpp index b37ec4326..65eb2b122 100644 --- a/src/apps/tlslegacy/TlsLegacySocketContext.cpp +++ b/src/apps/tlslegacy/TlsLegacySocketContext.cpp @@ -6,9 +6,8 @@ #include "TlsLegacySocketContext.h" -#include "SemanticLog.h" +#include "Log.h" #include "core/socket/stream/SocketConnection.h" -#include "log/Logger.h" #include @@ -31,7 +30,7 @@ namespace apps::tlslegacy { if (role == Role::CLIENT) { sendToPeer(TLS_HELLO); - snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() << ": sent TLS greeting"; + snode::log::application().debug() << getSocketConnection()->getConnectionName() << ": sent TLS greeting"; } } @@ -57,8 +56,8 @@ namespace apps::tlslegacy { } sendToPeer(payload); - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << getSocketConnection()->getConnectionName() << ": trying post-TLS legacy payload: " << payload; } }, @@ -68,14 +67,14 @@ namespace apps::tlslegacy { void TlsLegacySocketContext::onClientLine(const std::string& line) { if (line == TLS_ACK && !tlsReplySeen) { tlsReplySeen = true; - snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() + snode::log::application().debug() << getSocketConnection()->getConnectionName() << ": got TLS ack, initiating TLS shutdown handshake (close_notify) " << line; shutdownWrite(); startLegacyRetryTimer(LEGACY_HELLO); } else if (line == LEGACY_ACK && !legacyReplySeen) { legacyReplySeen = true; legacyRetryTimer.cancel(); - snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() + snode::log::application().debug() << getSocketConnection()->getConnectionName() << ": got LEGACY ack -> post-TLS plaintext path works " << line; shutdownWrite(); } @@ -85,14 +84,14 @@ namespace apps::tlslegacy { if (line == TLS_HELLO && !tlsReplySeen) { tlsReplySeen = true; sendToPeer(TLS_ACK); - snode::semantic::appLog().debug() << getSocketConnection()->getConnectionName() + snode::log::application().debug() << getSocketConnection()->getConnectionName() << ": TLS phase complete, waiting for peer close_notify " << line; } else if (line == LEGACY_HELLO && !legacyPayloadSeen) { legacyPayloadSeen = true; legacyRetryTimer.cancel(); sendToPeer(LEGACY_ACK); - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << getSocketConnection()->getConnectionName() << ": received LEGACY payload after TLS shutdown " << line; } shutdownWrite(); diff --git a/src/apps/tlslegacy/tlslegacyclient.cpp b/src/apps/tlslegacy/tlslegacyclient.cpp index ef459dde7..b935d8daa 100644 --- a/src/apps/tlslegacy/tlslegacyclient.cpp +++ b/src/apps/tlslegacy/tlslegacyclient.cpp @@ -4,10 +4,9 @@ * 2020, 2021, 2022, 2023, 2024, 2025, 2026 */ -#include "SemanticLog.h" +#include "Log.h" #include "TlsLegacySocketContext.h" #include "core/SNodeC.h" -#include "log/Logger.h" #include "net/in/stream/tls/SocketClient.h" int main(int argc, char* argv[]) { @@ -28,9 +27,9 @@ int main(int argc, char* argv[]) { client.connect([instanceName = client.getConfig()->getInstanceName()](const SocketClient::SocketAddress& socketAddress, const core::socket::State& state) { if (state == core::socket::State::OK) { - snode::semantic::appLog().info() << instanceName << ": connected to " << socketAddress.toString(); + snode::log::application().info() << instanceName << ": connected to " << socketAddress.toString(); } else if (state == core::socket::State::ERROR) { - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); } }); diff --git a/src/apps/tlslegacy/tlslegacyserver.cpp b/src/apps/tlslegacy/tlslegacyserver.cpp index 3d612d056..40f340e2c 100644 --- a/src/apps/tlslegacy/tlslegacyserver.cpp +++ b/src/apps/tlslegacy/tlslegacyserver.cpp @@ -4,10 +4,9 @@ * 2020, 2021, 2022, 2023, 2024, 2025, 2026 */ -#include "SemanticLog.h" +#include "Log.h" #include "TlsLegacySocketContext.h" #include "core/SNodeC.h" -#include "log/Logger.h" #include "net/in/stream/tls/SocketServer.h" int main(int argc, char* argv[]) { @@ -28,9 +27,9 @@ int main(int argc, char* argv[]) { server.listen([instanceName = server.getConfig()->getInstanceName()](const SocketServer::SocketAddress& socketAddress, const core::socket::State& state) { if (state == core::socket::State::OK) { - snode::semantic::appLog().info() << instanceName << ": listening on " << socketAddress.toString(); + snode::log::application().info() << instanceName << ": listening on " << socketAddress.toString(); } else if (state == core::socket::State::ERROR) { - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); } }); diff --git a/src/apps/warema-jalousien.cpp b/src/apps/warema-jalousien.cpp index dc8f78ac9..b9c164917 100644 --- a/src/apps/warema-jalousien.cpp +++ b/src/apps/warema-jalousien.cpp @@ -39,12 +39,11 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "express/legacy/in/WebApp.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -72,8 +71,8 @@ int main(int argc, char* argv[]) { // tls::WebApp wa; webApp.get("/jalousien/:id", [] APPLICATION(req, res) { - snode::semantic::appLog().debug() << "Param: " << req->param("id"); - snode::semantic::appLog().debug() << "Qurey: " << req->query("action"); + snode::log::application().debug() << "Param: " << req->param("id"); + snode::log::application().debug() << "Qurey: " << req->query("action"); std::string arguments = "aircontrol -t " + jalousien[req->param("id")] + "_" + actions[req->query("action")]; @@ -104,16 +103,16 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << ": disabled"; + snode::log::application().info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() + snode::log::application().critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } diff --git a/src/apps/websocket/echoclient.cpp b/src/apps/websocket/echoclient.cpp index b5ad8f507..f9e7a14e1 100644 --- a/src/apps/websocket/echoclient.cpp +++ b/src/apps/websocket/echoclient.cpp @@ -39,14 +39,13 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/SNodeC.h" #include "web/http/legacy/in/Client.h" #include "web/http/tls/in/Client.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #endif /* DOXYGEN_SHOULD_SKIP_THIS */ @@ -65,7 +64,7 @@ int main(int argc, char* argv[]) { [](const std::shared_ptr& req) { const std::string connectionName = req->getSocketContext()->getSocketConnection()->getConnectionName(); - snode::semantic::appLog().debug() << connectionName << ": OnRequestBegin"; + snode::log::application().debug() << connectionName << ": OnRequestBegin"; req->set("Sec-WebSocket-Protocol", "subprotocol, echo"); @@ -73,41 +72,41 @@ int main(int argc, char* argv[]) { "/ws", "websocket", [connectionName](bool success) { - snode::semantic::appLog().debug() + snode::log::application().debug() << connectionName << ": HTTP Upgrade (http -> websocket) start " << (success ? "success" : "failed"); }, [connectionName]([[maybe_unused]] const std::shared_ptr& req, const std::shared_ptr& res, [[maybe_unused]] bool success) { - snode::semantic::appLog().debug() << connectionName << ": Upgrade success:"; + snode::log::application().debug() << connectionName << ": Upgrade success:"; - snode::semantic::appLog().debug() << connectionName << ": Requested: " << req->header("upgrade"); - snode::semantic::appLog().debug() << connectionName << ": Selected: " << res->get("upgrade"); + snode::log::application().debug() << connectionName << ": Requested: " << req->header("upgrade"); + snode::log::application().debug() << connectionName << ": Selected: " << res->get("upgrade"); }, [connectionName](const std::shared_ptr&, const std::string& message) { - snode::semantic::appLog().debug() << connectionName << ": Request parse error: " << message; + snode::log::application().debug() << connectionName << ": Request parse error: " << message; }); }, []([[maybe_unused]] const std::shared_ptr& req) { const std::string connectionName = req->getConnectionName(); - snode::semantic::appLog().debug() << connectionName << ": OnRequestEnd"; + snode::log::application().debug() << connectionName << ": OnRequestEnd"; }); legacyClient.connect([instanceName = legacyClient.getConfig()->getInstanceName()](const LegacySocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << " connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << " connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << " disabled"; + snode::log::application().info() << instanceName << " disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); // Connection:keep-alive\r\n\r\n" @@ -123,7 +122,7 @@ int main(int argc, char* argv[]) { [](const std::shared_ptr& req) { const std::string connectionName = req->getSocketContext()->getSocketConnection()->getConnectionName(); - snode::semantic::appLog().debug() << connectionName << ": OnRequestBegin"; + snode::log::application().debug() << connectionName << ": OnRequestBegin"; req->set("Sec-WebSocket-Protocol", "subprotocol, echo"); @@ -131,7 +130,7 @@ int main(int argc, char* argv[]) { "/ws", "websocket", [connectionName](bool success) { - snode::semantic::appLog().debug() + snode::log::application().debug() << connectionName << ": HTTP Upgrade (http -> websocket) start " << (success ? "success" : "failed"); }, [connectionName]([[maybe_unused]] const std::shared_ptr& req, @@ -139,29 +138,29 @@ int main(int argc, char* argv[]) { [[maybe_unused]] bool success) { }, [connectionName](const std::shared_ptr&, const std::string& message) { - snode::semantic::appLog().debug() << connectionName << ": Request parse error: " << message; + snode::log::application().debug() << connectionName << ": Request parse error: " << message; }); }, []([[maybe_unused]] const std::shared_ptr& req) { const std::string connectionName = req->getConnectionName(); - snode::semantic::appLog().debug() << connectionName << ": OnRequestEnd"; + snode::log::application().debug() << connectionName << ": OnRequestEnd"; }); tlsClient.connect([instanceName = tlsClient.getConfig()->getInstanceName()](const TLSSocketAddress& socketAddress, const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << " connected to '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << " connected to '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << " disabled"; + snode::log::application().info() << instanceName << " disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }); // Connection:keep-alive\r\n\r\n" diff --git a/src/apps/websocket/echoserver.cpp b/src/apps/websocket/echoserver.cpp index 6cc9f15c4..f2c5ebad9 100644 --- a/src/apps/websocket/echoserver.cpp +++ b/src/apps/websocket/echoserver.cpp @@ -39,14 +39,13 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "express/legacy/in/WebApp.h" #include "express/middleware/VerboseRequest.h" #include "express/tls/in/WebApp.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -73,13 +72,13 @@ int main(int argc, char* argv[]) { res->upgrade(req, [req, res, connectionName](const std::string& name) { if (!name.empty()) { - snode::semantic::appLog().debug() << connectionName << ": Successful upgrade:"; - snode::semantic::appLog().debug() << connectionName << ": Requested: " << req->get("upgrade"); - snode::semantic::appLog().debug() << connectionName << ": Selected: " << name; + snode::log::application().debug() << connectionName << ": Successful upgrade:"; + snode::log::application().debug() << connectionName << ": Requested: " << req->get("upgrade"); + snode::log::application().debug() << connectionName << ": Selected: " << name; res->end(); } else { - snode::semantic::appLog().debug() << connectionName << ": Can not upgrade to any of '" << req->get("upgrade") << "'"; + snode::log::application().debug() << connectionName << ": Can not upgrade to any of '" << req->get("upgrade") << "'"; res->sendStatus(404); } @@ -87,18 +86,18 @@ int main(int argc, char* argv[]) { }); legacyApp.get("/", [] APPLICATION(req, res) { - snode::semantic::appLog().debug() << "HTTP GET on " + snode::log::application().debug() << "HTTP GET on " << "/"; if (req->url == "/" || req->url == "/index.html") { req->url = "/wstest.html"; } - snode::semantic::appLog().debug() << CMAKE_CURRENT_SOURCE_DIR "/html" + req->url; + snode::log::application().debug() << CMAKE_CURRENT_SOURCE_DIR "/html" + req->url; res->sendFile(CMAKE_CURRENT_SOURCE_DIR "/html" + req->url, [req, res](int errnum) { if (errnum == 0) { - snode::semantic::appLog().debug() << req->url; + snode::log::application().debug() << req->url; } else { - snode::semantic::appLog().debug() << "HTTP response send file failed: " << std::strerror(errnum); + snode::log::application().debug() << "HTTP response send file failed: " << std::strerror(errnum); res->sendStatus(404); } }); @@ -109,23 +108,23 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << " disabled"; + snode::log::application().info() << instanceName << " disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }) .getFlowController(); - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Legacy Routes:"; for (std::string route : legacyApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); @@ -149,13 +148,13 @@ int main(int argc, char* argv[]) { res->upgrade(req, [req, res, connectionName](const std::string& name) { if (!name.empty()) { - snode::semantic::appLog().debug() << connectionName << ": Upgrade success:"; - snode::semantic::appLog().debug() << connectionName << ": Requested: " << req->get("upgrade"); - snode::semantic::appLog().debug() << connectionName << ": Selected: " << name; + snode::log::application().debug() << connectionName << ": Upgrade success:"; + snode::log::application().debug() << connectionName << ": Requested: " << req->get("upgrade"); + snode::log::application().debug() << connectionName << ": Selected: " << name; res->end(); } else { - snode::semantic::appLog().debug() << connectionName << ": Can not upgrade to any of '" << req->get("upgrade") << "'"; + snode::log::application().debug() << connectionName << ": Can not upgrade to any of '" << req->get("upgrade") << "'"; res->sendStatus(404); } @@ -167,12 +166,12 @@ int main(int argc, char* argv[]) { req->url = "/wstest.html"; } - snode::semantic::appLog().debug() << CMAKE_CURRENT_SOURCE_DIR "/html" + req->url; + snode::log::application().debug() << CMAKE_CURRENT_SOURCE_DIR "/html" + req->url; res->sendFile(CMAKE_CURRENT_SOURCE_DIR "/html" + req->url, [req, res](int errnum) { if (errnum == 0) { - snode::semantic::appLog().debug() << req->url; + snode::log::application().debug() << req->url; } else { - snode::semantic::appLog().debug() << "HTTP response send file failed: " << std::strerror(errnum); + snode::log::application().debug() << "HTTP response send file failed: " << std::strerror(errnum); res->sendStatus(404); } }); @@ -183,23 +182,23 @@ int main(int argc, char* argv[]) { const core::socket::State& state) { switch (state) { case core::socket::State::OK: - snode::semantic::appLog().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; + snode::log::application().info() << instanceName << " listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::appLog().info() << instanceName << " disabled"; + snode::log::application().info() << instanceName << " disabled"; break; case core::socket::State::ERROR: - snode::semantic::appLog().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().error() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::appLog().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); + snode::log::application().critical() << instanceName << " " << socketAddress.toString() << ": " << state.what(); break; } }) .getFlowController(); - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Tls Routes:"; for (std::string route : legacyApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); diff --git a/src/apps/websocket/subprotocol/client/echo/Echo.cpp b/src/apps/websocket/subprotocol/client/echo/Echo.cpp index 04f90decf..bbb164e7b 100644 --- a/src/apps/websocket/subprotocol/client/echo/Echo.cpp +++ b/src/apps/websocket/subprotocol/client/echo/Echo.cpp @@ -41,11 +41,10 @@ #include "Echo.h" -#include "SemanticLog.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include "utils/system/signal.h" #include @@ -62,28 +61,28 @@ namespace apps::websocket::subprotocol::echo::client { } void Echo::onConnected() { - snode::semantic::appLog().debug() << "Echo connected"; + snode::log::application().debug() << "Echo connected"; sendMessage("Welcome to SimpleChat"); sendMessage("====================="); } void Echo::onMessageStart(int opCode) { - snode::semantic::appLog().debug() << "Message Start - OpCode: " << opCode; + snode::log::application().debug() << "Message Start - OpCode: " << opCode; } void Echo::onMessageData(const char* chunk, std::size_t chunkLen) { data += std::string(chunk, chunkLen); - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Message Fragment: " << std::string(chunk, chunkLen); } } void Echo::onMessageEnd() { - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Message Data: " << data; } @@ -94,15 +93,15 @@ namespace apps::websocket::subprotocol::echo::client { } void Echo::onMessageError(uint16_t errnum) { - snode::semantic::appLog().debug() << "Message error: " << errnum; + snode::log::application().debug() << "Message error: " << errnum; } void Echo::onDisconnected() { - snode::semantic::appLog().debug() << "Echo disconnected:"; + snode::log::application().debug() << "Echo disconnected:"; } bool Echo::onSignal(int sig) { - snode::semantic::appLog().debug() << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" + snode::log::application().debug() << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig << ")"; sendClose(); diff --git a/src/apps/websocket/subprotocol/server/echo/Echo.cpp b/src/apps/websocket/subprotocol/server/echo/Echo.cpp index 5a1e04aa0..83ccaec10 100644 --- a/src/apps/websocket/subprotocol/server/echo/Echo.cpp +++ b/src/apps/websocket/subprotocol/server/echo/Echo.cpp @@ -41,11 +41,10 @@ #include "Echo.h" -#include "SemanticLog.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include "utils/system/signal.h" #include @@ -62,25 +61,25 @@ namespace apps::websocket::subprotocol::echo::server { } void Echo::onConnected() { - snode::semantic::appLog().debug() << "Echo connected"; + snode::log::application().debug() << "Echo connected"; } void Echo::onMessageStart(int opCode) { - snode::semantic::appLog().debug() << "Message Start - OpCode: " << opCode; + snode::log::application().debug() << "Message Start - OpCode: " << opCode; } void Echo::onMessageData(const char* chunk, std::size_t chunkLen) { data += std::string(chunk, chunkLen); - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Message Fragment: " << std::string(chunk, chunkLen); } } void Echo::onMessageEnd() { - auto log = snode::semantic::appLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::application(); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Message Data: " << data; } @@ -95,15 +94,15 @@ namespace apps::websocket::subprotocol::echo::server { } void Echo::onMessageError(uint16_t errnum) { - snode::semantic::appLog().debug() << "Message error: " << errnum; + snode::log::application().debug() << "Message error: " << errnum; } void Echo::onDisconnected() { - snode::semantic::appLog().debug() << "Echo disconnected:"; + snode::log::application().debug() << "Echo disconnected:"; } bool Echo::onSignal(int sig) { - snode::semantic::appLog().debug() << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" + snode::log::application().debug() << "SubProtocol 'echo' exit due to '" << strsignal(sig) << "' (SIG" << utils::system::sigabbrev_np(sig) << " = " << sig << ")"; sendClose(); diff --git a/src/core/DynamicLoader.cpp b/src/core/DynamicLoader.cpp index 0e7ca27c2..1ecf31f80 100644 --- a/src/core/DynamicLoader.cpp +++ b/src/core/DynamicLoader.cpp @@ -41,11 +41,10 @@ #include "core/DynamicLoader.h" -#include "SemanticLog.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -86,7 +85,7 @@ namespace core { ++lib.refCount; lib.closePending = false; - snode::semantic::coreSystemLog().trace() + snode::log::framework("core.system").trace() << "DynLoader dlOpen: " << lib.fileName << ": already open (refCount=" << lib.refCount << ")"; handle = lib.handle; } else { @@ -105,9 +104,9 @@ namespace core { dlOpenedLibraries.emplace(canonicalFile, lib); dlOpenedLibrariesByHandle.emplace(handle, canonicalFile); - snode::semantic::coreSystemLog().trace() << "DynLoader dlOpen: " << libFile << ": success"; + snode::log::framework("core.system").trace() << "DynLoader dlOpen: " << libFile << ": success"; } else { - snode::semantic::coreSystemLog().trace() << "DynLoader dlOpen: " << libFile << ": " << DynamicLoader::dlError(); + snode::log::framework("core.system").trace() << "DynLoader dlOpen: " << libFile << ": " << DynamicLoader::dlError(); } } @@ -116,15 +115,15 @@ namespace core { void DynamicLoader::dlCloseDelayed(void* handle) { if (handle == nullptr) { - snode::semantic::coreSystemLog().trace() << "DynLoader dlCloseDelayed: handle is nullptr"; + snode::log::framework("core.system").trace() << "DynLoader dlCloseDelayed: handle is nullptr"; } else { auto itHandle = dlOpenedLibrariesByHandle.find(handle); if (itHandle == dlOpenedLibrariesByHandle.end()) { - snode::semantic::coreSystemLog().trace() << "DynLoader dlCloseDelayed: " << handle << ": not opened using dlOpen"; + snode::log::framework("core.system").trace() << "DynLoader dlCloseDelayed: " << handle << ": not opened using dlOpen"; } else { auto itLib = dlOpenedLibraries.find(itHandle->second); if (itLib == dlOpenedLibraries.end()) { - snode::semantic::coreSystemLog().trace() + snode::log::framework("core.system").trace() << "DynLoader: dlCloseDelayed: internal error: handle known but library record missing"; } else { Library& lib = itLib->second; @@ -136,9 +135,9 @@ namespace core { if (lib.refCount == 0) { lib.closePending = true; closeQueue.push_back(lib.canonicalFileName); - snode::semantic::coreSystemLog().trace() << "DynLoader dlCloseDelayed: " << lib.fileName; + snode::log::framework("core.system").trace() << "DynLoader dlCloseDelayed: " << lib.fileName; } else { - snode::semantic::coreSystemLog().trace() + snode::log::framework("core.system").trace() << "DynLoader dlCloseDelayed: " << lib.fileName << ": still referenced (refCount=" << lib.refCount << ")"; } } @@ -150,15 +149,15 @@ namespace core { int ret = 0; if (handle == nullptr) { - snode::semantic::coreSystemLog().trace() << "DynLoader dlClose: handle is nullptr"; + snode::log::framework("core.system").trace() << "DynLoader dlClose: handle is nullptr"; } else { auto itHandle = dlOpenedLibrariesByHandle.find(handle); if (itHandle == dlOpenedLibrariesByHandle.end()) { - snode::semantic::coreSystemLog().trace() << "DynLoader dlClose: " << handle << ": not opened using dlOpen"; + snode::log::framework("core.system").trace() << "DynLoader dlClose: " << handle << ": not opened using dlOpen"; } else { auto itLib = dlOpenedLibraries.find(itHandle->second); if (itLib == dlOpenedLibraries.end()) { - snode::semantic::coreSystemLog().trace() + snode::log::framework("core.system").trace() << "DynLoader dlClose: internal error: handle known but library record missing"; } else { Library& lib = itLib->second; @@ -168,7 +167,7 @@ namespace core { } if (lib.refCount != 0) { - snode::semantic::coreSystemLog().trace() + snode::log::framework("core.system").trace() << "DynLoader dlClose: " << lib.fileName << ": still referenced (refCount=" << lib.refCount << ")"; } else { lib.closePending = false; @@ -205,9 +204,9 @@ namespace core { ret = realExecDlClose(library); if (ret != 0) { - snode::semantic::coreSystemLog().trace() << "DynLoader dlClose: " << DynamicLoader::dlError(); + snode::log::framework("core.system").trace() << "DynLoader dlClose: " << DynamicLoader::dlError(); } else { - snode::semantic::coreSystemLog().trace() << "DynLoader dlClose: " << library.fileName << ": success"; + snode::log::framework("core.system").trace() << "DynLoader dlClose: " << library.fileName << ": success"; } return ret; diff --git a/src/core/eventreceiver/ReadEventReceiver.cpp b/src/core/eventreceiver/ReadEventReceiver.cpp index 2b749e52b..9fbb6434a 100644 --- a/src/core/eventreceiver/ReadEventReceiver.cpp +++ b/src/core/eventreceiver/ReadEventReceiver.cpp @@ -44,6 +44,7 @@ #include "core/EventLoop.h" #include "core/EventMultiplexer.h" #include "log/SemanticLogger.h" +#include "log/detail/Native.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -59,6 +60,12 @@ namespace core::eventreceiver { timeout) { } + ReadEventReceiver::ReadEventReceiver(const std::string& name, + const snode::log::Scope& logScope, + const utils::Timeval& timeout) + : ReadEventReceiver(name, snode::log::detail::nativeScope(logScope), timeout) { + } + void ReadEventReceiver::readTimeout() { disable(); } diff --git a/src/core/eventreceiver/ReadEventReceiver.h b/src/core/eventreceiver/ReadEventReceiver.h index 737c41359..75922ed44 100644 --- a/src/core/eventreceiver/ReadEventReceiver.h +++ b/src/core/eventreceiver/ReadEventReceiver.h @@ -48,6 +48,10 @@ namespace logger { struct LogScope; } +namespace snode::log { + struct Scope; +} + #ifndef DOXYGEN_SHOULD_SKIP_THIS #include "utils/Timeval.h" @@ -61,6 +65,7 @@ namespace core::eventreceiver { class ReadEventReceiver : public core::DescriptorEventReceiver { protected: ReadEventReceiver(const std::string& name, logger::LogScope logScope, const utils::Timeval& timeout); + ReadEventReceiver(const std::string& name, const snode::log::Scope& logScope, const utils::Timeval& timeout); virtual void readTimeout(); diff --git a/src/core/eventreceiver/WriteEventReceiver.cpp b/src/core/eventreceiver/WriteEventReceiver.cpp index 356854a9a..f7f35e215 100644 --- a/src/core/eventreceiver/WriteEventReceiver.cpp +++ b/src/core/eventreceiver/WriteEventReceiver.cpp @@ -44,6 +44,7 @@ #include "core/EventLoop.h" #include "core/EventMultiplexer.h" #include "log/SemanticLogger.h" +#include "log/detail/Native.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -59,6 +60,12 @@ namespace core::eventreceiver { timeout) { } + WriteEventReceiver::WriteEventReceiver(const std::string& name, + const snode::log::Scope& logScope, + const utils::Timeval& timeout) + : WriteEventReceiver(name, snode::log::detail::nativeScope(logScope), timeout) { + } + void WriteEventReceiver::writeTimeout() { disable(); } diff --git a/src/core/eventreceiver/WriteEventReceiver.h b/src/core/eventreceiver/WriteEventReceiver.h index 1a9046850..921a8b47b 100644 --- a/src/core/eventreceiver/WriteEventReceiver.h +++ b/src/core/eventreceiver/WriteEventReceiver.h @@ -48,6 +48,10 @@ namespace logger { struct LogScope; } +namespace snode::log { + struct Scope; +} + #ifndef DOXYGEN_SHOULD_SKIP_THIS #include "utils/Timeval.h" @@ -61,6 +65,7 @@ namespace core::eventreceiver { class WriteEventReceiver : public core::DescriptorEventReceiver { protected: WriteEventReceiver(const std::string& name, logger::LogScope logScope, const utils::Timeval& timeout); + WriteEventReceiver(const std::string& name, const snode::log::Scope& logScope, const utils::Timeval& timeout); virtual void writeTimeout(); diff --git a/src/core/socket/stream/SocketAcceptor.hpp b/src/core/socket/stream/SocketAcceptor.hpp index d02d44b3f..3e682e924 100644 --- a/src/core/socket/stream/SocketAcceptor.hpp +++ b/src/core/socket/stream/SocketAcceptor.hpp @@ -39,13 +39,12 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/State.h" #include "core/socket/stream/SocketAcceptor.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include "utils/PreserveErrno.h" #include @@ -109,13 +108,13 @@ namespace core::socket::stream { core::socket::State state = core::socket::STATE_OK; bool bindSucceeded = false; - snode::semantic::coreSocketLog().debug() << config->getInstanceName() << " Listen: starting"; + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " Listen: starting"; configuredAddress = config->Local::getSocketAddress(); if (physicalServerSocket.open(config->getSocketOptions(), PhysicalServerSocket::Flags::NONBLOCK) < 0) { const int errnum = errno; - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Error, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Error, errnum) << config->getInstanceName() << " open " << configuredAddress.toString(); switch (errnum) { @@ -130,12 +129,12 @@ namespace core::socket::stream { break; } } else { - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " open " << configuredAddress.toString() << ": success"; if (physicalServerSocket.bind(configuredAddress) < 0) { const int errnum = errno; - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Error, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Error, errnum) << config->getInstanceName() << " bind " << configuredAddress.toString(); switch (errnum) { @@ -154,7 +153,7 @@ namespace core::socket::stream { const std::string configuredAddressString = configuredAddress.toString(); const std::string effectiveBindAddressString = physicalServerSocket.getBindAddress().toString(); - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " bind " << configuredAddressString << (configuredAddressString == effectiveBindAddressString ? "" : " (effective: " + effectiveBindAddressString + ")") @@ -162,7 +161,7 @@ namespace core::socket::stream { if (physicalServerSocket.listen(config->getBacklog()) < 0) { const int errnum = errno; - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Error, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Error, errnum) << config->getInstanceName() << " listen " << physicalServerSocket.getBindAddress().toString(); switch (errnum) { @@ -174,15 +173,15 @@ namespace core::socket::stream { break; } } else { - snode::semantic::coreSocketLog().debug() << config->getInstanceName() << " listen " + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " listen " << physicalServerSocket.getBindAddress().toString() << ": success"; if (enable(physicalServerSocket.getFd())) { - snode::semantic::coreSocketLog().debug() << config->getInstanceName() << " enable " + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " enable " << physicalServerSocket.getBindAddress().toString() << ": success"; log().info("listener started"); } else { - snode::semantic::coreSocketLog().error() + snode::log::framework("core.socket", snode::log::Boundary::Connection).error() << config->getInstanceName() << " enable " << physicalServerSocket.getBindAddress().toString() << ": failed. No valid descriptor created"; @@ -200,7 +199,7 @@ namespace core::socket::stream { if (configuredAddress.useNext()) { onStatus(currentLocalAddress, (state | core::socket::State::NO_RETRY)); - snode::semantic::coreSocketLog().info() + snode::log::framework("core.socket", snode::log::Boundary::Connection).info() << config->getInstanceName() << ": Using next SocketAddress: " << config->Local::getSocketAddress().toString(); useNextSocketAddress(); @@ -211,13 +210,13 @@ namespace core::socket::stream { core::socket::State state = core::socket::STATE(badSocketAddress.getState(), badSocketAddress.getErrnum(), badSocketAddress.what()); - snode::semantic::coreSocketLog().error() << state.what(); + snode::log::framework("core.socket", snode::log::Boundary::Connection).error() << state.what(); log().debug("listener start failed"); onStatus({}, state); } } else { - snode::semantic::coreSocketLog().debug() << config->getInstanceName() << ": disabled"; + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << ": disabled"; onStatus({}, core::socket::STATE_DISABLED); } @@ -249,15 +248,15 @@ namespace core::socket::stream { socketConnection->log().info("transport connected"); - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " accept " << physicalServerSocket.getBindAddress().toString() << ": success"; - snode::semantic::coreSocketLog().debug() << " " << socketConnection->getRemoteAddress().toString() << " -> " + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << " " << socketConnection->getRemoteAddress().toString() << " -> " << socketConnection->getLocalAddress().toString(); onConnect(socketConnection); onConnected(socketConnection); } else if (errnum != EINTR && errnum != EAGAIN && errnum != EWOULDBLOCK) { - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Warn, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Warning, errnum) << config->getInstanceName() << " accept " << physicalServerSocket.getBindAddress().toString(); } } while (--acceptsPerTick > 0); diff --git a/src/core/socket/stream/SocketConnector.hpp b/src/core/socket/stream/SocketConnector.hpp index 01b6fbf2c..6e1b3ca82 100644 --- a/src/core/socket/stream/SocketConnector.hpp +++ b/src/core/socket/stream/SocketConnector.hpp @@ -39,13 +39,12 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/State.h" #include "core/socket/stream/SocketConnector.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include "utils/PreserveErrno.h" #include @@ -110,7 +109,7 @@ namespace core::socket::stream { try { core::socket::State state = core::socket::STATE_OK; - snode::semantic::coreSocketLog().debug() << config->getInstanceName() << " Connect: starting"; + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " Connect: starting"; SocketAddress configuredLocalAddress = config->Local::getSocketAddress(); @@ -119,7 +118,7 @@ namespace core::socket::stream { if (physicalClientSocket.open(config->getSocketOptions(), PhysicalClientSocket::Flags::NONBLOCK) < 0) { const int errnum = errno; - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Debug, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Debug, errnum) << config->getInstanceName() << " open " << configuredLocalAddress.toString(); switch (errnum) { @@ -136,12 +135,12 @@ namespace core::socket::stream { finishAttempt("connection attempt failed", configuredLocalAddress, state); } else { - snode::semantic::coreSocketLog().trace() + snode::log::framework("core.socket", snode::log::Boundary::Connection).trace() << config->getInstanceName() << " open " << configuredLocalAddress.toString() << ": success"; if (physicalClientSocket.bind(configuredLocalAddress) < 0) { const int errnum = errno; - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Debug, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Debug, errnum) << config->getInstanceName() << " bind " << configuredLocalAddress.toString(); switch (errnum) { @@ -158,7 +157,7 @@ namespace core::socket::stream { const std::string configuredLocalAddressString = configuredLocalAddress.toString(); const std::string effectiveBindAddressString = physicalClientSocket.getBindAddress().toString(); - snode::semantic::coreSocketLog().trace() + snode::log::framework("core.socket", snode::log::Boundary::Connection).trace() << config->getInstanceName() << " bind " << configuredLocalAddressString << (configuredLocalAddressString == effectiveBindAddressString ? "" @@ -168,7 +167,7 @@ namespace core::socket::stream { const int connectResult = physicalClientSocket.connect(remoteAddress); const int errnum = errno; if (connectResult < 0 && !PhysicalClientSocket::connectInProgress(errnum)) { - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Debug, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Debug, errnum) << config->getInstanceName() << " connect " << remoteAddress.toString(); switch (errnum) { case EADDRINUSE: @@ -188,7 +187,7 @@ namespace core::socket::stream { if (remoteAddress.useNext()) { finishAttempt("connection attempt failed", currentRemoteAddress, state | core::socket::State::NO_RETRY); - snode::semantic::coreSocketLog().info() + snode::log::framework("core.socket", snode::log::Boundary::Connection).info() << config->getInstanceName() << ": Using next SocketAddress: " << remoteAddress.toString(); useNextSocketAddress(); @@ -196,15 +195,15 @@ namespace core::socket::stream { finishAttempt("connection attempt failed", currentRemoteAddress, state); } } else { - snode::semantic::coreSocketLog().trace() + snode::log::framework("core.socket", snode::log::Boundary::Connection).trace() << config->getInstanceName() << " connect " << remoteAddress.toString() << ": success"; if (PhysicalClientSocket::connectInProgress(errnum)) { if (enable(physicalClientSocket.getFd())) { - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " enable " << remoteAddress.toString(false) << ": success"; } else { - snode::semantic::coreSocketLog().error() + snode::log::framework("core.socket", snode::log::Boundary::Connection).error() << config->getInstanceName() << " enable " << remoteAddress.toString() << ": failed. No valid descriptor created"; @@ -216,9 +215,9 @@ namespace core::socket::stream { SocketConnection* socketConnection = new SocketConnection(std::move(physicalClientSocket), onDisconnect, allocateConnectionId(), config); - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " connect " << remoteAddress.toString() << ": success"; - snode::semantic::coreSocketLog().debug() << " " << socketConnection->getLocalAddress().toString() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << " " << socketConnection->getLocalAddress().toString() << " -> " << socketConnection->getRemoteAddress().toString(); finishAttempt("connection attempt succeeded", remoteAddress, state); @@ -235,7 +234,7 @@ namespace core::socket::stream { core::socket::State state = core::socket::STATE(badSocketAddress.getState(), badSocketAddress.getErrnum(), badSocketAddress.what()); - snode::semantic::coreSocketLog().error() << state.what(); + snode::log::framework("core.socket", snode::log::Boundary::Connection).error() << state.what(); finishAttempt("connection attempt failed", {}, state); } @@ -243,12 +242,12 @@ namespace core::socket::stream { core::socket::State state = core::socket::STATE(badSocketAddress.getState(), badSocketAddress.getErrnum(), badSocketAddress.what()); - snode::semantic::coreSocketLog().error() << state.what(); + snode::log::framework("core.socket", snode::log::Boundary::Connection).error() << state.what(); finishAttempt("connection attempt failed", {}, state); } } else { - snode::semantic::coreSocketLog().debug() << config->getInstanceName() << ": disabled"; + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << ": disabled"; onStatus({}, core::socket::STATE_DISABLED); } @@ -274,9 +273,9 @@ namespace core::socket::stream { if (errnum == 0) { SocketConnection* socketConnection = new SocketConnection(std::move(physicalClientSocket), onDisconnect, allocateConnectionId(), config); - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " connect " << remoteAddress.toString() << ": success"; - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << " " << socketConnection->getLocalAddress().toString() << " -> " << socketConnection->getRemoteAddress().toString(); finishAttempt("connection attempt succeeded", remoteAddress, core::socket::STATE_OK); @@ -288,7 +287,7 @@ namespace core::socket::stream { disable(); } else if (PhysicalClientSocket::connectInProgress(errnum)) { - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " connect " << remoteAddress.toString() << ": in progress:"; } else { SocketAddress currentRemoteAddress = remoteAddress; @@ -310,19 +309,19 @@ namespace core::socket::stream { } if (remoteAddress.useNext()) { - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Debug, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Debug, errnum) << config->getInstanceName() << " connect '" << remoteAddress.toString(); finishAttempt("connection attempt failed", currentRemoteAddress, state | core::socket::State::NO_RETRY); - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " using next SocketAddress: " << config->Remote::getSocketAddress().toString(); useNextSocketAddress(); disable(); } else { - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Debug, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Debug, errnum) << config->getInstanceName() << " connect " << remoteAddress.toString(); finishAttempt("connection attempt failed", currentRemoteAddress, state); @@ -332,7 +331,7 @@ namespace core::socket::stream { } } else { const int errnum = errno; - snode::semantic::sysError(snode::semantic::coreSocketLog(), logger::LogLevel::Debug, errnum) + snode::log::framework("core.socket", snode::log::Boundary::Connection).systemError(snode::log::Level::Debug, errnum) << config->getInstanceName() << " getsockopt syscall error: '" << remoteAddress.toString() << "'"; finishAttempt("connection attempt failed", remoteAddress, core::socket::STATE_FATAL); @@ -351,17 +350,17 @@ namespace core::socket::stream { typename Config, template typename SocketConnection> void SocketConnector::connectTimeout() { - snode::semantic::coreSocketLog().trace() << config->getInstanceName() << " connect timeout " << remoteAddress.toString(); + snode::log::framework("core.socket", snode::log::Boundary::Connection).trace() << config->getInstanceName() << " connect timeout " << remoteAddress.toString(); SocketAddress currentRemoteAddress = remoteAddress; if (remoteAddress.useNext()) { finishAttempt("connection attempt timed out"); - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " using next SocketAddress: '" << config->Remote::getSocketAddress().toString() << "'"; useNextSocketAddress(); } else { - snode::semantic::coreSocketLog().debug() + snode::log::framework("core.socket", snode::log::Boundary::Connection).debug() << config->getInstanceName() << " connect timeout '" << remoteAddress.toString() << "'"; errno = ETIMEDOUT; diff --git a/src/database/mariadb/MariaDBLibrary.cpp b/src/database/mariadb/MariaDBLibrary.cpp index 62725db6c..7dbea76c6 100644 --- a/src/database/mariadb/MariaDBLibrary.cpp +++ b/src/database/mariadb/MariaDBLibrary.cpp @@ -41,8 +41,7 @@ #include "database/mariadb/MariaDBLibrary.h" -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -60,7 +59,7 @@ namespace database::mariadb { std::call_once(initOnce, []() { const int rc = mysql_library_init(0, nullptr, nullptr); if (rc != 0) { - snode::semantic::mariaDbLog().error() << "mysql_library_init failed (rc=" << rc << ")"; + snode::log::framework("db.mariadb", snode::log::Boundary::Connection).error() << "mysql_library_init failed (rc=" << rc << ")"; // Best effort: proceed; subsequent mysql_* calls may fail. } diff --git a/src/express/dispatcher/ApplicationDispatcher.cpp b/src/express/dispatcher/ApplicationDispatcher.cpp index 9a8c5ac13..81b266166 100644 --- a/src/express/dispatcher/ApplicationDispatcher.cpp +++ b/src/express/dispatcher/ApplicationDispatcher.cpp @@ -41,7 +41,7 @@ #include "express/dispatcher/ApplicationDispatcher.h" -#include "SemanticLog.h" +#include "Log.h" #include "core/socket/stream/SocketConnection.h" #include "express/Controller.h" #include "express/Request.h" @@ -52,7 +52,6 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -71,16 +70,21 @@ namespace express::dispatcher { bool strictRouting, bool caseInsensitiveRouting, bool mergeParams) { - snode::semantic::expressLog().trace() << "======================= APPLICATION DISPATCH ======================="; - snode::semantic::expressLog(*controller.getResponse()->getSocketContext()->getSocketConnection()).trace() << "Application dispatch"; - snode::semantic::expressLog().trace() << " Request Method: " << controller.getRequest()->method; - snode::semantic::expressLog().trace() << " Request Url: " << controller.getRequest()->url; - snode::semantic::expressLog().trace() << " Request Path: " << controller.getRequest()->path; - snode::semantic::expressLog().trace() << " Mountpoint Method: " << mountPoint.method; - snode::semantic::expressLog().trace() << " Mountpoint Path: " << mountPoint.relativeMountPath; - snode::semantic::expressLog().trace() << " StrictRouting: " << strictRouting; - snode::semantic::expressLog().trace() << " CaseInsensitiveRouting: " << caseInsensitiveRouting; - snode::semantic::expressLog().trace() << " MergeParams: " << mergeParams; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "======================= APPLICATION DISPATCH ======================="; + snode::log::forConnection(*controller.getResponse()->getSocketContext()->getSocketConnection(), + "express", + snode::log::Origin::Framework, + snode::log::Boundary::Application) + .trace() + << "Application dispatch"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Request Method: " << controller.getRequest()->method; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Request Url: " << controller.getRequest()->url; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Request Path: " << controller.getRequest()->path; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Mountpoint Method: " << mountPoint.method; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Mountpoint Path: " << mountPoint.relativeMountPath; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " StrictRouting: " << strictRouting; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " CaseInsensitiveRouting: " << caseInsensitiveRouting; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " MergeParams: " << mergeParams; bool dispatched = false; @@ -92,7 +96,7 @@ namespace express::dispatcher { matchMountPoint(controller, mountPoint.relativeMountPath, mountPoint, regex, names, strictRouting, caseInsensitiveRouting); if (match.requestMatched) { - snode::semantic::expressLog().trace() << "----------------------- APPLICATION MATCH -----------------------"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "----------------------- APPLICATION MATCH -----------------------"; dispatched = true; @@ -114,10 +118,10 @@ namespace express::dispatcher { } } else { - snode::semantic::expressLog().trace() << "----------------------- APPLICATION NOMATCH -----------------------"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "----------------------- APPLICATION NOMATCH -----------------------"; } } else { - snode::semantic::expressLog().trace() << "----------------------- APPLICATION NOMATCH -----------------------"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "----------------------- APPLICATION NOMATCH -----------------------"; } return dispatched; diff --git a/src/express/dispatcher/MiddlewareDispatcher.cpp b/src/express/dispatcher/MiddlewareDispatcher.cpp index 39d6402fc..c40152bf0 100644 --- a/src/express/dispatcher/MiddlewareDispatcher.cpp +++ b/src/express/dispatcher/MiddlewareDispatcher.cpp @@ -41,7 +41,7 @@ #include "express/dispatcher/MiddlewareDispatcher.h" -#include "SemanticLog.h" +#include "Log.h" #include "core/socket/stream/SocketConnection.h" #include "express/Next.h" #include "express/Request.h" @@ -52,7 +52,6 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -71,16 +70,21 @@ namespace express::dispatcher { bool strictRouting, bool caseInsensitiveRouting, bool mergeParams) { - snode::semantic::expressLog().trace() << "======================= MIDDLEWARE DISPATCH ======================="; - snode::semantic::expressLog(*controller.getResponse()->getSocketContext()->getSocketConnection()).trace() << "Middleware dispatch"; - snode::semantic::expressLog().trace() << " Request Method: " << controller.getRequest()->method; - snode::semantic::expressLog().trace() << " Request Url: " << controller.getRequest()->url; - snode::semantic::expressLog().trace() << " Request Path: " << controller.getRequest()->path; - snode::semantic::expressLog().trace() << " Mountpoint Method: " << mountPoint.method; - snode::semantic::expressLog().trace() << " Mountpoint Path: " << mountPoint.relativeMountPath; - snode::semantic::expressLog().trace() << " StrictRouting: " << strictRouting; - snode::semantic::expressLog().trace() << " CaseInsensitiveRouting: " << caseInsensitiveRouting; - snode::semantic::expressLog().trace() << " MergeParams: " << mergeParams; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "======================= MIDDLEWARE DISPATCH ======================="; + snode::log::forConnection(*controller.getResponse()->getSocketContext()->getSocketConnection(), + "express", + snode::log::Origin::Framework, + snode::log::Boundary::Application) + .trace() + << "Middleware dispatch"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Request Method: " << controller.getRequest()->method; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Request Url: " << controller.getRequest()->url; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Request Path: " << controller.getRequest()->path; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Mountpoint Method: " << mountPoint.method; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Mountpoint Path: " << mountPoint.relativeMountPath; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " StrictRouting: " << strictRouting; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " CaseInsensitiveRouting: " << caseInsensitiveRouting; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " MergeParams: " << mergeParams; bool dispatched = false; @@ -92,7 +96,7 @@ namespace express::dispatcher { matchMountPoint(controller, mountPoint.relativeMountPath, mountPoint, regex, names, strictRouting, caseInsensitiveRouting); if (match.requestMatched) { - snode::semantic::expressLog().trace() << "----------------------- MIDDLEWARE MATCH -----------------------"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "----------------------- MIDDLEWARE MATCH -----------------------"; dispatched = true; @@ -110,7 +114,7 @@ namespace express::dispatcher { // If next() was called synchronously continue current route-tree traversal if ((next.controller.getFlags() & express::Controller::NEXT) != 0) { - snode::semantic::expressLog().trace() << "Express: M - Next called - set to NO MATCH"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "Express: M - Next called - set to NO MATCH"; dispatched = false; controller = next.controller; } @@ -122,10 +126,10 @@ namespace express::dispatcher { } } else { - snode::semantic::expressLog().trace() << "----------------------- MIDDLEWARE NOMATCH -----------------------"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "----------------------- MIDDLEWARE NOMATCH -----------------------"; } } else { - snode::semantic::expressLog().trace() << "----------------------- MIDDLEWARE NOMATCH -----------------------"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "----------------------- MIDDLEWARE NOMATCH -----------------------"; } return dispatched; diff --git a/src/express/dispatcher/RouterDispatcher.cpp b/src/express/dispatcher/RouterDispatcher.cpp index 4f7882825..1787137c3 100644 --- a/src/express/dispatcher/RouterDispatcher.cpp +++ b/src/express/dispatcher/RouterDispatcher.cpp @@ -41,7 +41,7 @@ #include "express/dispatcher/RouterDispatcher.h" -#include "SemanticLog.h" +#include "Log.h" #include "core/socket/stream/SocketConnection.h" #include "express/Controller.h" #include "express/Request.h" @@ -52,7 +52,6 @@ #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -70,16 +69,21 @@ namespace express::dispatcher { [[maybe_unused]] bool strictRoutingUnused, [[maybe_unused]] bool caseInsensitiveRoutingUnused, [[maybe_unused]] bool mergeParamsUnused) { - snode::semantic::expressLog().trace() << "======================= ROUTER DISPATCH ======================="; - snode::semantic::expressLog(*controller.getResponse()->getSocketContext()->getSocketConnection()).trace() << "Router dispatch"; - snode::semantic::expressLog().trace() << " Request Method: " << controller.getRequest()->method; - snode::semantic::expressLog().trace() << " Request Url: " << controller.getRequest()->url; - snode::semantic::expressLog().trace() << " Request Path: " << controller.getRequest()->path; - snode::semantic::expressLog().trace() << " Mountpoint Method: " << mountPoint.method; - snode::semantic::expressLog().trace() << " Mountpoint Path: " << mountPoint.relativeMountPath; - snode::semantic::expressLog().trace() << " StrictRouting: " << this->strictRouting; - snode::semantic::expressLog().trace() << " CaseInsensitiveRouting: " << this->caseInsensitiveRouting; - snode::semantic::expressLog().trace() << " MergeParams: " << this->mergeParams; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "======================= ROUTER DISPATCH ======================="; + snode::log::forConnection(*controller.getResponse()->getSocketContext()->getSocketConnection(), + "express", + snode::log::Origin::Framework, + snode::log::Boundary::Application) + .trace() + << "Router dispatch"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Request Method: " << controller.getRequest()->method; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Request Url: " << controller.getRequest()->url; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Request Path: " << controller.getRequest()->path; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Mountpoint Method: " << mountPoint.method; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " Mountpoint Path: " << mountPoint.relativeMountPath; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " StrictRouting: " << this->strictRouting; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " CaseInsensitiveRouting: " << this->caseInsensitiveRouting; + snode::log::framework("express", snode::log::Boundary::Application).trace() << " MergeParams: " << this->mergeParams; bool dispatched = false; @@ -90,7 +94,7 @@ namespace express::dispatcher { controller, mountPoint.relativeMountPath, mountPoint, regex, names, this->strictRouting, this->caseInsensitiveRouting); if (match.requestMatched) { - snode::semantic::expressLog().trace() << "----------------------- ROUTER MATCH -----------------------"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "----------------------- ROUTER MATCH -----------------------"; dispatched = true; @@ -113,10 +117,10 @@ namespace express::dispatcher { controller.getResponse()->sendStatus(400); } } else { - snode::semantic::expressLog().trace() << "----------------------- ROUTER NOMATCH -----------------------"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "----------------------- ROUTER NOMATCH -----------------------"; } } else { - snode::semantic::expressLog().trace() << "----------------------- ROUTER NOMATCH -----------------------"; + snode::log::framework("express", snode::log::Boundary::Application).trace() << "----------------------- ROUTER NOMATCH -----------------------"; } return dispatched; diff --git a/src/express/legacy/in/Server.cpp b/src/express/legacy/in/Server.cpp index dca1f81b7..e4fed360f 100644 --- a/src/express/legacy/in/Server.cpp +++ b/src/express/legacy/in/Server.cpp @@ -41,8 +41,7 @@ #include "express/legacy/in/Server.h" -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -71,24 +70,24 @@ namespace express::legacy::in { } else { switch (state) { case core::socket::State::OK: - snode::semantic::expressLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::expressLog().info() << instanceName << ": disabled"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::expressLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::framework("express", snode::log::Boundary::Application).error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::expressLog().critical() + snode::log::framework("express", snode::log::Boundary::Application).critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - auto log = snode::semantic::expressLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::framework("express", snode::log::Boundary::Application); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Instance: " << instanceName; for (std::string route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); diff --git a/src/express/legacy/in6/Server.cpp b/src/express/legacy/in6/Server.cpp index a460ec8d0..7ad8a7d88 100644 --- a/src/express/legacy/in6/Server.cpp +++ b/src/express/legacy/in6/Server.cpp @@ -41,8 +41,7 @@ #include "express/legacy/in6/Server.h" -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -71,24 +70,24 @@ namespace express::legacy::in6 { } else { switch (state) { case core::socket::State::OK: - snode::semantic::expressLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::expressLog().info() << instanceName << ": disabled"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::expressLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::framework("express", snode::log::Boundary::Application).error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::expressLog().critical() + snode::log::framework("express", snode::log::Boundary::Application).critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - auto log = snode::semantic::expressLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::framework("express", snode::log::Boundary::Application); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Instance: " << instanceName; for (std::string route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); diff --git a/src/express/legacy/rc/Server.cpp b/src/express/legacy/rc/Server.cpp index 28a8f22e0..88a7d69c0 100644 --- a/src/express/legacy/rc/Server.cpp +++ b/src/express/legacy/rc/Server.cpp @@ -41,8 +41,7 @@ #include "express/legacy/rc/Server.h" -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -71,24 +70,24 @@ namespace express::legacy::rc { } else { switch (state) { case core::socket::State::OK: - snode::semantic::expressLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::expressLog().info() << instanceName << ": disabled"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::expressLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::framework("express", snode::log::Boundary::Application).error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::expressLog().critical() + snode::log::framework("express", snode::log::Boundary::Application).critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - auto log = snode::semantic::expressLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::framework("express", snode::log::Boundary::Application); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Instance: " << instanceName; for (std::string route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); diff --git a/src/express/legacy/un/Server.cpp b/src/express/legacy/un/Server.cpp index 2ee9d8342..13ff1fb79 100644 --- a/src/express/legacy/un/Server.cpp +++ b/src/express/legacy/un/Server.cpp @@ -41,8 +41,7 @@ #include "express/legacy/un/Server.h" -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -71,24 +70,24 @@ namespace express::legacy::un { } else { switch (state) { case core::socket::State::OK: - snode::semantic::expressLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::expressLog().info() << instanceName << ": disabled"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::expressLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::framework("express", snode::log::Boundary::Application).error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::expressLog().critical() + snode::log::framework("express", snode::log::Boundary::Application).critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - auto log = snode::semantic::expressLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::framework("express", snode::log::Boundary::Application); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Instance: " << instanceName; for (std::string route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); diff --git a/src/express/middleware/StaticMiddleware.cpp b/src/express/middleware/StaticMiddleware.cpp index 942624482..b054a3ad5 100644 --- a/src/express/middleware/StaticMiddleware.cpp +++ b/src/express/middleware/StaticMiddleware.cpp @@ -41,14 +41,13 @@ #include "express/middleware/StaticMiddleware.h" -#include "SemanticLog.h" +#include "Log.h" #include "core/socket/stream/SocketConnection.h" #include "web/http/http_utils.h" #include "web/http/server/SocketContext.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include @@ -67,7 +66,12 @@ namespace express::middleware { &stdCookies = this->stdCookies, &connectionState = this->defaultConnectionState, &fallThrough = this->fallThrough] MIDDLEWARE(req, res, next) { - snode::semantic::expressLog(*res->getSocketContext()->getSocketConnection()).debug() << "Express " << req->method; + snode::log::forConnection(*res->getSocketContext()->getSocketConnection(), + "express", + snode::log::Origin::Framework, + snode::log::Boundary::Application) + .debug() + << "Express " << req->method; if (req->method != "GET") { if (fallThrough) { @@ -95,7 +99,11 @@ namespace express::middleware { if (index.empty()) { res->status(404).send("Unsupported resource: " + req->url + "\n"); } else { - snode::semantic::expressLog(*res->getSocketContext()->getSocketConnection()).info() + snode::log::forConnection(*res->getSocketContext()->getSocketConnection(), + "express", + snode::log::Origin::Framework, + snode::log::Boundary::Application) + .info() << "Express StaticMiddleware Redirecting: " << req->url << " -> " << req->originalPath + (!req->originalPath.empty() && req->originalPath.back() != '/' && index.front() != '/' ? "/" : "") + @@ -113,11 +121,18 @@ namespace express::middleware { const std::string decodedPath = httputils::url_decode(req->path); res->sendFile(root + decodedPath, [&root, decodedPath, req, res, &next, &fallThrough](int ret) { if (ret == 0) { - snode::semantic::expressLog(*res->getSocketContext()->getSocketConnection()).info() + snode::log::forConnection(*res->getSocketContext()->getSocketConnection(), + "express", + snode::log::Origin::Framework, + snode::log::Boundary::Application) + .info() << "Express StaticMiddleware: GET " << req->url + " -> " << root + decodedPath; } else { - snode::semantic::sysError( - snode::semantic::expressLog(*res->getSocketContext()->getSocketConnection()), logger::LogLevel::Error, ret) + snode::log::forConnection(*res->getSocketContext()->getSocketConnection(), + "express", + snode::log::Origin::Framework, + snode::log::Boundary::Application) + .systemError(snode::log::Level::Error, ret) << "Express StaticMiddleware " << req->url + " -> " << root + decodedPath; if (fallThrough) { diff --git a/src/express/middleware/VerboseRequest.cpp b/src/express/middleware/VerboseRequest.cpp index 527908597..56ebc63da 100644 --- a/src/express/middleware/VerboseRequest.cpp +++ b/src/express/middleware/VerboseRequest.cpp @@ -41,14 +41,12 @@ #include "express/middleware/VerboseRequest.h" -#include "SemanticLog.h" +#include "Log.h" #include "core/socket/stream/SocketConnection.h" #include "web/http/server/SocketContext.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" -#include "log/SemanticLogger.h" #include "web/http/http_utils.h" #include @@ -59,8 +57,11 @@ namespace express::middleware { VerboseRequest::VerboseRequest(Details details) { use("/", [details] MIDDLEWARE(req, res, next) { - auto log = snode::semantic::expressLog(*res->getSocketContext()->getSocketConnection()); - if (log.enabled(logger::LogLevel::Debug)) { + auto log = snode::log::forConnection(*res->getSocketContext()->getSocketConnection(), + "express", + snode::log::Origin::Framework, + snode::log::Boundary::Application); + if (log.enabled(snode::log::Level::Debug)) { const std::string prefix = "Express VerboseMiddleware: " + req->method + " " + req->url + " " + req->httpVersion + "\n"; const auto formatted = httputils::toStringPresentation( req->method, @@ -71,8 +72,8 @@ namespace express::middleware { (details & Details::W_TRAILER) == Details::W_TRAILER ? req->trailer : web::http::CiStringMap(), (details & Details::W_COOKIES) == Details::W_COOKIES ? req->cookies : web::http::CiStringMap(), (details & Details::W_CONTENT) == Details::W_CONTENT ? req->body : std::vector()); - log.emit(logger::LogLevel::Debug, - logger::PresentedMessage{.plain = prefix + formatted.plain, .terminal = prefix + formatted.terminal}); + log.emit(snode::log::Level::Debug, + snode::log::Message{.plain = prefix + formatted.plain, .terminal = prefix + formatted.terminal}); } next(); diff --git a/src/express/tls/in/Server.cpp b/src/express/tls/in/Server.cpp index 4d0501f47..f06d5fee2 100644 --- a/src/express/tls/in/Server.cpp +++ b/src/express/tls/in/Server.cpp @@ -41,8 +41,7 @@ #include "express/tls/in/Server.h" -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -71,24 +70,24 @@ namespace express::tls::in { } else { switch (state) { case core::socket::State::OK: - snode::semantic::expressLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::expressLog().info() << instanceName << ": disabled"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::expressLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::framework("express", snode::log::Boundary::Application).error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::expressLog().critical() + snode::log::framework("express", snode::log::Boundary::Application).critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - auto log = snode::semantic::expressLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::framework("express", snode::log::Boundary::Application); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Instance: " << instanceName; for (std::string route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); diff --git a/src/express/tls/in6/Server.cpp b/src/express/tls/in6/Server.cpp index dc4c8c446..34d9bffb5 100644 --- a/src/express/tls/in6/Server.cpp +++ b/src/express/tls/in6/Server.cpp @@ -41,8 +41,7 @@ #include "express/tls/in6/Server.h" -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -71,24 +70,24 @@ namespace express::tls::in6 { } else { switch (state) { case core::socket::State::OK: - snode::semantic::expressLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::expressLog().info() << instanceName << ": disabled"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::expressLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::framework("express", snode::log::Boundary::Application).error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::expressLog().critical() + snode::log::framework("express", snode::log::Boundary::Application).critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - auto log = snode::semantic::expressLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::framework("express", snode::log::Boundary::Application); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Instance: " << instanceName; for (std::string route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); diff --git a/src/express/tls/rc/Server.cpp b/src/express/tls/rc/Server.cpp index 1753d58f0..21eab681b 100644 --- a/src/express/tls/rc/Server.cpp +++ b/src/express/tls/rc/Server.cpp @@ -41,8 +41,7 @@ #include "express/tls/rc/Server.h" -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -71,24 +70,24 @@ namespace express::tls::rc { } else { switch (state) { case core::socket::State::OK: - snode::semantic::expressLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::expressLog().info() << instanceName << ": disabled"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::expressLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::framework("express", snode::log::Boundary::Application).error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::expressLog().critical() + snode::log::framework("express", snode::log::Boundary::Application).critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - auto log = snode::semantic::expressLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::framework("express", snode::log::Boundary::Application); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Instance: " << instanceName; for (std::string route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); diff --git a/src/express/tls/un/Server.cpp b/src/express/tls/un/Server.cpp index 020a145ff..5d4778514 100644 --- a/src/express/tls/un/Server.cpp +++ b/src/express/tls/un/Server.cpp @@ -41,8 +41,7 @@ #include "express/tls/un/Server.h" -#include "SemanticLog.h" -#include "log/Logger.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS @@ -71,24 +70,24 @@ namespace express::tls::un { } else { switch (state) { case core::socket::State::OK: - snode::semantic::expressLog().info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": listening on '" << socketAddress.toString() << "'"; break; case core::socket::State::DISABLED: - snode::semantic::expressLog().info() << instanceName << ": disabled"; + snode::log::framework("express", snode::log::Boundary::Application).info() << instanceName << ": disabled"; break; case core::socket::State::ERROR: - snode::semantic::expressLog().error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); + snode::log::framework("express", snode::log::Boundary::Application).error() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; case core::socket::State::FATAL: - snode::semantic::expressLog().critical() + snode::log::framework("express", snode::log::Boundary::Application).critical() << instanceName << ": " << socketAddress.toString() << ": " << state.what(); break; } } }); - auto log = snode::semantic::expressLog(); - if (log.enabled(logger::LogLevel::Trace)) { + auto log = snode::log::framework("express", snode::log::Boundary::Application); + if (log.enabled(snode::log::Level::Trace)) { log.trace() << "Instance: " << instanceName; for (std::string route : webApp.getRoutes()) { route.erase(std::remove(route.begin(), route.end(), '$'), route.end()); diff --git a/src/log/CMakeLists.txt b/src/log/CMakeLists.txt index 61af39e5a..a144f4027 100644 --- a/src/log/CMakeLists.txt +++ b/src/log/CMakeLists.txt @@ -65,7 +65,7 @@ FetchContent_MakeAvailable(spdlog) set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${TMP_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}) -set(LOGGER_CPP Logger.cpp SemanticLogger.cpp LogScopeOwner.cpp detail/SpdlogBackend.cpp) +set(LOGGER_CPP Log.cpp Logger.cpp SemanticLogger.cpp LogScopeOwner.cpp detail/SpdlogBackend.cpp) set(LOGGER_H Logger.h SemanticLogger.h LogScopeOwner.h detail/SpdlogBackend.h) diff --git a/src/log/Log.cpp b/src/log/Log.cpp new file mode 100644 index 000000000..d6ee8d7b1 --- /dev/null +++ b/src/log/Log.cpp @@ -0,0 +1,237 @@ +#include "Log.h" + +#include "log/LogScopeOwner.h" +#include "log/Logger.h" +#include "log/detail/Native.h" + +#include + +namespace snode::log { + namespace { + logger::LogLevel nativeLevel(const Level level) noexcept { + switch (level) { + case Level::Trace: + return logger::LogLevel::Trace; + case Level::Debug: + return logger::LogLevel::Debug; + case Level::Info: + return logger::LogLevel::Info; + case Level::Warning: + return logger::LogLevel::Warn; + case Level::Error: + return logger::LogLevel::Error; + case Level::Critical: + return logger::LogLevel::Critical; + case Level::Off: + return logger::LogLevel::Off; + } + return logger::LogLevel::Off; + } + + logger::LogOrigin nativeOrigin(const Origin origin) noexcept { + return origin == Origin::Framework ? logger::LogOrigin::Framework : logger::LogOrigin::Application; + } + + logger::LogBoundary nativeBoundary(const Boundary boundary) noexcept { + switch (boundary) { + case Boundary::Application: + return logger::LogBoundary::Application; + case Boundary::Configuration: + return logger::LogBoundary::Configuration; + case Boundary::Instance: + return logger::LogBoundary::Instance; + case Boundary::Connection: + return logger::LogBoundary::Connection; + case Boundary::Context: + return logger::LogBoundary::Context; + case Boundary::System: + return logger::LogBoundary::System; + } + return logger::LogBoundary::System; + } + + logger::LogRole nativeRole(const std::optional& role) noexcept { + if (!role) { + return logger::LogRole::Unknown; + } + return *role == Role::Server ? logger::LogRole::Server : logger::LogRole::Client; + } + } // namespace + + logger::LogScope detail::nativeScope(const Scope& scope) noexcept { + return {nativeOrigin(scope.origin), + nativeBoundary(scope.boundary), + scope.component, + scope.identity.instance ? std::string_view(*scope.identity.instance) : std::string_view(), + nativeRole(scope.identity.role), + scope.identity.connection ? std::string_view(*scope.identity.connection) : std::string_view()}; + } + + class Logger::Impl { + public: + explicit Impl(logger::BoundaryLogger logger) + : logger(std::move(logger)) { + } + + logger::BoundaryLogger logger; + }; + + Stream::Stream(std::unique_ptr state) + : state(std::move(state)) { + } + + Stream::Stream(Stream&& other) noexcept = default; + + Stream& Stream::operator=(Stream&& other) noexcept { + if (this != &other) { + flush(); + state = std::move(other.state); + } + return *this; + } + + Stream::~Stream() { + flush(); + } + + void Stream::flush() { + if (state && !state->emitted) { + state->emitted = true; + if (state->enabled) { + state->emit(state->buffer.str()); + } + } + } + + Logger::Logger(std::shared_ptr impl) + : impl(std::move(impl)) { + } + + bool Logger::enabled(const Level level) const noexcept { + return impl && impl->logger.enabled(nativeLevel(level)); + } + + void Logger::emit(const Level level, Message message) const { + if (!enabled(level)) { + return; + } + impl->logger.emit(nativeLevel(level), + logger::PresentedMessage{.plain = std::move(message.plain), + .terminal = message.terminal ? std::move(*message.terminal) : std::string()}); + } + + Stream Logger::stream(const Level level) const { + const bool isEnabled = enabled(level); + auto state = std::make_unique(); + state->enabled = isEnabled; + if (isEnabled) { + const auto implementation = impl; + state->emit = [implementation, level](std::string message) { + implementation->logger.emit(nativeLevel(level), std::move(message)); + }; + } + return Stream(std::move(state)); + } + + Stream Logger::trace() const { + return stream(Level::Trace); + } + Stream Logger::debug() const { + return stream(Level::Debug); + } + Stream Logger::info() const { + return stream(Level::Info); + } + Stream Logger::warn() const { + return stream(Level::Warning); + } + Stream Logger::error() const { + return stream(Level::Error); + } + Stream Logger::critical() const { + return stream(Level::Critical); + } + + Stream Logger::systemError(const Level level, std::error_code error) const { + const bool isEnabled = enabled(level); + auto state = std::make_unique(); + state->enabled = isEnabled; + if (isEnabled) { + const auto implementation = impl; + state->emit = [implementation, level, error = std::move(error)](std::string message) { + implementation->logger.sysError(nativeLevel(level), error, "{}", message); + }; + } + return Stream(std::move(state)); + } + + Stream Logger::systemError(const Level level, const int errorNumber) const { + return systemError(level, std::error_code(errorNumber, std::generic_category())); + } + + void Logger::write(const Level level, std::string message) const { + if (enabled(level)) { + impl->logger.emit(nativeLevel(level), std::move(message)); + } + } + + void Logger::writeEvent(const Level level, std::string eventName, std::string message) const { + if (!enabled(level)) { + return; + } + logger::LogRecordOptions options; + options.event = std::move(eventName); + impl->logger.emit(nativeLevel(level), std::move(message), std::move(options)); + } + + void Logger::writeSystemError(const Level level, std::error_code error, std::string message) const { + if (enabled(level)) { + impl->logger.sysError(nativeLevel(level), std::move(error), "{}", message); + } + } + + Logger makeLogger(Scope scope) { + auto owner = logger::LogScopeOwner::fromScope(detail::nativeScope(scope)); + return Logger(std::make_shared(owner.logger(logger::Logger::semanticSink()))); + } + + Logger application(std::string component, Identity identity) { + return makeLogger({Origin::Application, Boundary::Application, std::move(component), std::move(identity)}); + } + + Logger framework(std::string component, const Boundary boundary, Identity identity) { + return makeLogger({Origin::Framework, boundary, std::move(component), std::move(identity)}); + } + + void configure(const Settings& settings) { + logger::Logger::init(); + logger::LogManager::init(); + logger::LogManager::setGlobalLevel(nativeLevel(settings.level)); + logger::LogManager::setFormat(settings.format == Format::Json ? logger::LogManager::Format::Json : logger::LogManager::Format::Text); + for (const auto& rule : settings.originLevels) { + logger::LogManager::setOriginLevel(nativeOrigin(rule.origin), nativeLevel(rule.level)); + } + for (const auto& rule : settings.boundaryLevels) { + logger::LogManager::setBoundaryLevel(nativeBoundary(rule.boundary), nativeLevel(rule.level)); + } + for (const auto& rule : settings.componentLevels) { + logger::LogManager::setComponentLevel(rule.name, nativeLevel(rule.level)); + } + for (const auto& rule : settings.instanceLevels) { + logger::LogManager::setInstanceLevel(rule.name, nativeLevel(rule.level)); + } + logger::Logger::setQuiet(settings.quiet); + if (settings.color == ColorMode::Always) { + logger::Logger::setDisableColor(false); + } else if (settings.color == ColorMode::Never) { + logger::Logger::setDisableColor(true); + } + if (settings.file && !settings.file->empty()) { + logger::Logger::logToFile(*settings.file); + } else { + logger::Logger::disableLogToFile(); + } + logger::LogManager::freeze(); + } + +} // namespace snode::log diff --git a/src/log/detail/Native.h b/src/log/detail/Native.h new file mode 100644 index 000000000..3d6b7b781 --- /dev/null +++ b/src/log/detail/Native.h @@ -0,0 +1,13 @@ +#ifndef SNODEC_LOG_DETAIL_NATIVE_H +#define SNODEC_LOG_DETAIL_NATIVE_H + +#include "Log.h" +#include "log/SemanticLogger.h" + +namespace snode::log::detail { + + logger::LogScope nativeScope(const Scope& scope) noexcept; + +} // namespace snode::log::detail + +#endif // SNODEC_LOG_DETAIL_NATIVE_H diff --git a/src/log/detail/SpdlogBackend.cpp b/src/log/detail/SpdlogBackend.cpp index 923e43f72..08aa594e0 100644 --- a/src/log/detail/SpdlogBackend.cpp +++ b/src/log/detail/SpdlogBackend.cpp @@ -14,11 +14,8 @@ #include "log/detail/SpdlogBackend.h" #include -#include -#include #include #include -#include #include #include #include @@ -27,68 +24,6 @@ #endif /* DOXYGEN_SHOULD_SKIP_THIS */ namespace { - using Clock = std::chrono::steady_clock; - - std::string levelName(const ::logger::Level level) { - switch (level) { - case ::logger::Level::TRACE: - return "TRACE "; - case ::logger::Level::DEBUG: - return "DEBUG "; - case ::logger::Level::INFO: - return "INFO "; - case ::logger::Level::WARNING: - return "WARNING"; - case ::logger::Level::ERROR: - return "ERROR "; - case ::logger::Level::FATAL: - return "FATAL "; - case ::logger::Level::VERBOSE: - return "VERBOSE"; - } - return ""; - } - - Color::Code levelColor(const ::logger::Level level) { - switch (level) { - case ::logger::Level::TRACE: - return Color::Code::FG_MAGENTA; - case ::logger::Level::DEBUG: - return Color::Code::FG_LIGHT_GREEN; - case ::logger::Level::INFO: - return Color::Code::FG_LIGHT_YELLOW; - case ::logger::Level::WARNING: - return Color::Code::FG_YELLOW; - case ::logger::Level::ERROR: - return Color::Code::FG_RED; - case ::logger::Level::FATAL: - return Color::Code::FG_LIGHT_RED; - case ::logger::Level::VERBOSE: - return Color::Code::FG_WHITE; - } - return Color::Code::FG_WHITE; - } - - spdlog::level::level_enum mapLegacyLevel(const ::logger::Level level) { - switch (level) { - case ::logger::Level::TRACE: - return spdlog::level::trace; - case ::logger::Level::DEBUG: - return spdlog::level::debug; - case ::logger::Level::INFO: - return spdlog::level::info; - case ::logger::Level::WARNING: - return spdlog::level::warn; - case ::logger::Level::ERROR: - return spdlog::level::err; - case ::logger::Level::FATAL: - return spdlog::level::critical; - case ::logger::Level::VERBOSE: - return spdlog::level::info; - } - return spdlog::level::info; - } - std::optional mapSemanticLevel(const ::logger::LogLevel level) { switch (level) { case ::logger::LogLevel::Trace: @@ -114,32 +49,7 @@ namespace logger::detail { class SpdlogBackend::Impl { public: - class TickFlagFormatter final : public spdlog::custom_flag_formatter { - public: - explicit TickFlagFormatter(const Impl& backend) - : backend(backend) { - } - - void format(const spdlog::details::log_msg&, const std::tm&, spdlog::memory_buf_t& dest) override { - const std::string tick = backend.tick(); - dest.append(tick.data(), tick.data() + static_cast(tick.size())); - } - - std::unique_ptr clone() const override { - return spdlog::details::make_unique(backend); - } - - private: - const Impl& backend; - }; - void init() { - startTime = Clock::now(); - stdoutSink = std::make_shared(); - stdoutLogger = std::make_shared("snodec-stdout", stdoutSink); - stdoutLogger->set_level(spdlog::level::trace); - stdoutLogger->set_formatter(legacyFormatter()); - semanticStdoutSink = std::make_shared(); semanticStdoutLogger = std::make_shared("snodec-semantic-stdout", semanticStdoutSink); semanticStdoutLogger->set_level(spdlog::level::trace); @@ -179,11 +89,6 @@ namespace logger::detail { void setLogFile(const std::string& logFile) { constexpr std::size_t maxSize = 2 * 1024 * 1024; constexpr std::size_t maxFiles = 3; - fileSink = std::make_shared(logFile, maxSize, maxFiles); - fileLogger = std::make_shared("snodec-file", fileSink); - fileLogger->set_level(spdlog::level::trace); - fileLogger->set_formatter(legacyFormatter()); - semanticFileSink = std::make_shared(logFile, maxSize, maxFiles); semanticFileLogger = std::make_shared("snodec-semantic-file", semanticFileSink); semanticFileLogger->set_level(spdlog::level::trace); @@ -193,8 +98,6 @@ namespace logger::detail { void disableLogFile() { semanticFileLogger.reset(); semanticFileSink.reset(); - fileLogger.reset(); - fileSink.reset(); } bool shouldLog(const Level level) const { @@ -223,30 +126,6 @@ namespace logger::detail { return verboseLevel >= 0 && verboseLevel <= configuredVerboseLevel; } - void emitLegacy(const Level level, std::string message, const bool withErrno, const int errnoValue) { - if (!shouldLog(level)) { - return; - } - if (withErrno) { - message += ": "; - message += std::strerror(errnoValue); - } - if (level != Level::VERBOSE) { - std::string label = levelName(level); - if (!disableColor) { - label = Color::Code::FG_DEFAULT + (levelColor(level) + label) + Color::Code::FG_DEFAULT; - } - message = label + " " + message; - } - const auto spdlogLevel = mapLegacyLevel(level); - if (!quietMode && stdoutLogger) { - stdoutLogger->log(spdlogLevel, message); - } - if (fileLogger) { - fileLogger->log(spdlogLevel, message); - } - } - bool semanticStdoutUsesColor() const { return !quietMode && semanticStdoutLogger && !disableColor; } @@ -264,37 +143,13 @@ namespace logger::detail { } } - std::string tick() const { - if (tickResolver) { - return tickResolver(); - } - - const auto elapsed = std::chrono::duration_cast(Clock::now() - startTime).count(); - std::string tick = std::to_string(elapsed); - if (tick.size() < 13) { - tick.insert(0, 13 - tick.size(), '0'); - } - return tick; - } - - std::unique_ptr legacyFormatter() const { - auto formatter = std::make_unique(); - formatter->add_flag('*', *this).set_pattern("%Y-%m-%d %H:%M:%S %* %v"); - return formatter; - } - private: - std::shared_ptr stdoutSink; std::shared_ptr semanticStdoutSink; - std::shared_ptr fileSink; std::shared_ptr semanticFileSink; - std::shared_ptr stdoutLogger; - std::shared_ptr fileLogger; std::shared_ptr semanticStdoutLogger; std::shared_ptr semanticFileLogger; Logger::TickResolver tickResolver; - Clock::time_point startTime = Clock::now(); int configuredLogLevel = 0; int configuredVerboseLevel = 0; bool quietMode = false; @@ -335,10 +190,6 @@ namespace logger::detail { impl_->disableLogFile(); } - void SpdlogBackend::emitLegacy(const Level level, std::string message, const bool withErrno, const int errnoValue) { - impl_->emitLegacy(level, std::move(message), withErrno, errnoValue); - } - void SpdlogBackend::emitSemantic(const LogLevel level, const std::string& plainRecord, const std::string& coloredRecord) { impl_->emitSemantic(level, plainRecord, coloredRecord); } diff --git a/src/log/detail/SpdlogBackend.h b/src/log/detail/SpdlogBackend.h index 82b7fac16..4b0a23ff0 100644 --- a/src/log/detail/SpdlogBackend.h +++ b/src/log/detail/SpdlogBackend.h @@ -44,7 +44,6 @@ namespace logger::detail { void setLogFile(const std::string& logFile); void disableLogFile(); - void emitLegacy(Level level, std::string message, bool withErrno, int errnoValue); void emitSemantic(LogLevel level, const std::string& plainRecord, const std::string& coloredRecord); bool semanticStdoutUsesColor() const; diff --git a/src/net/config/ConfigPhysicalSocket.cpp b/src/net/config/ConfigPhysicalSocket.cpp index d94903fe5..1e26cee44 100644 --- a/src/net/config/ConfigPhysicalSocket.cpp +++ b/src/net/config/ConfigPhysicalSocket.cpp @@ -41,11 +41,10 @@ #include "ConfigPhysicalSocket.h" -#include "SemanticLog.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -85,7 +84,7 @@ namespace net::config { removeSocketOption(optLevel, optName); } } catch (CLI::OptionNotFound& err) { - snode::semantic::netConfigLog().error() << err.what(); + snode::log::framework("net.config", snode::log::Boundary::Configuration).error() << err.what(); } }, description, diff --git a/src/net/config/stream/tls/ConfigSocketServer.hpp b/src/net/config/stream/tls/ConfigSocketServer.hpp index ec5572a17..5892b799b 100644 --- a/src/net/config/stream/tls/ConfigSocketServer.hpp +++ b/src/net/config/stream/tls/ConfigSocketServer.hpp @@ -39,12 +39,11 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "net/config/stream/tls/ConfigSocketServer.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -101,7 +100,7 @@ namespace net::config::stream::tls { sniCtxMap.insert(sslSans.begin(), sslSans.end()); for (const auto& [sni, ctx] : sniCtxMap) { - snode::semantic::tlsConfigLog().trace() + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).trace() << getInstanceName() << " SSL/TLS: SSL_CTX (M) sni for '" << sni << "' from master certificate installed"; } @@ -139,24 +138,24 @@ namespace net::config::stream::tls { sniCtxs.push_back(newCtx); sniCtxMap.insert_or_assign(domain, newCtx); - snode::semantic::tlsConfigLog().trace() + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).trace() << getInstanceName() << " SSL/TLS: SSL_CTX (E) sni for '" << domain << "' explicitly installed"; for (const auto& [san, ctx] : core::socket::stream::tls::ssl_get_sans(newCtx)) { sniCtxMap.insert_or_assign(san, ctx); - snode::semantic::tlsConfigLog().trace() + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).trace() << getInstanceName() << " SSL/TLS: SSL_CTX (S) sni for '" << san << "' from SAN installed"; } } else { - snode::semantic::tlsConfigLog().warn() + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).warn() << getInstanceName() << " SSL/TLS: Can not create SNI_SSL_CTX for domain '" << domain << "'"; } } } - snode::semantic::tlsConfigLog().trace() << getInstanceName() << " SSL/TLS: SNI list result:"; + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).trace() << getInstanceName() << " SSL/TLS: SNI list result:"; for (const auto& [sni, ctx] : sniCtxMap) { - snode::semantic::tlsConfigLog().trace() << " " << sni; + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).trace() << " " << sni; } } @@ -165,23 +164,23 @@ namespace net::config::stream::tls { template SSL_CTX* ConfigSocketServer::getSniCtx(const std::string& serverNameIndication) { - snode::semantic::tlsConfigLog().trace() + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).trace() << getInstanceName() << " SSL/TLS SNI: Lookup for sni='" << serverNameIndication << "' in sni certificates"; SSL_CTX* sniCtx = nullptr; std::map::iterator sniPairIt = std::find_if( sniCtxMap.begin(), sniCtxMap.end(), [&serverNameIndication, this](const std::pair& sniPair) -> bool { - snode::semantic::tlsConfigLog().trace() << getInstanceName() << " SSL/TLS SNI: .. " << sniPair.first.c_str(); + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).trace() << getInstanceName() << " SSL/TLS SNI: .. " << sniPair.first.c_str(); return core::socket::stream::tls::match(sniPair.first.c_str(), serverNameIndication.c_str()); }); if (sniPairIt != sniCtxMap.end()) { - snode::semantic::tlsConfigLog().trace() + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).trace() << getInstanceName() << " SSL/TLS SNI: found for " << serverNameIndication << " -> '" << sniPairIt->first << "'"; sniCtx = sniPairIt->second; } else { - snode::semantic::tlsConfigLog().warn() << getInstanceName() << " SSL/TL SNI: not found for " << serverNameIndication; + snode::log::framework("net.config.tls", snode::log::Boundary::Configuration).warn() << getInstanceName() << " SSL/TL SNI: not found for " << serverNameIndication; } return sniCtx; diff --git a/src/web/http/MimeTypes.cpp b/src/web/http/MimeTypes.cpp index d95ff0572..1020bad62 100644 --- a/src/web/http/MimeTypes.cpp +++ b/src/web/http/MimeTypes.cpp @@ -41,11 +41,10 @@ #include "web/http/MimeTypes.h" -#include "SemanticLog.h" +#include "Log.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include #include @@ -248,7 +247,7 @@ namespace web::http { MimeTypes::magic = magic_open(MAGIC_MIME); if (magic_load(magic, nullptr) != 0) { - snode::semantic::webHttpLog().debug() << "Cannot load magic database - " + std::string(magic_error(magic)); + snode::log::framework("web.http", snode::log::Boundary::Connection).debug() << "Cannot load magic database - " + std::string(magic_error(magic)); magic_close(magic); magic = nullptr; } diff --git a/src/web/http/SocketContextUpgradeFactorySelector.hpp b/src/web/http/SocketContextUpgradeFactorySelector.hpp index 2fc7d30fa..ef73a92ac 100644 --- a/src/web/http/SocketContextUpgradeFactorySelector.hpp +++ b/src/web/http/SocketContextUpgradeFactorySelector.hpp @@ -40,13 +40,12 @@ * THE SOFTWARE. */ -#include "SemanticLog.h" +#include "Log.h" #include "core/DynamicLoader.h" #include "web/http/SocketContextUpgradeFactorySelector.h" #ifndef DOXYGEN_SHOULD_SKIP_THIS -#include "log/Logger.h" #include "web/http/http_utils.h" #include @@ -98,20 +97,20 @@ namespace web::http { if (socketContextUpgradeFactory != nullptr) { if (add(socketContextUpgradeFactory, handle)) { - snode::semantic::webHttpLog().trace() << "SocketContextUpgradeFactory create success: " << socketContextUpgradeName; + snode::log::framework("web.http", snode::log::Boundary::Connection).trace() << "SocketContextUpgradeFactory create success: " << socketContextUpgradeName; } else { - snode::semantic::webHttpLog().trace() + snode::log::framework("web.http", snode::log::Boundary::Connection).trace() << "SocketContextUpgradeFactory already existing: " << socketContextUpgradeName; delete socketContextUpgradeFactory; socketContextUpgradeFactory = nullptr; core::DynamicLoader::dlClose(handle); } } else { - snode::semantic::webHttpLog().error() << "SocketContextUpgradeFactory create failed: " << socketContextUpgradeName; + snode::log::framework("web.http", snode::log::Boundary::Connection).error() << "SocketContextUpgradeFactory create failed: " << socketContextUpgradeName; core::DynamicLoader::dlClose(handle); } } else { - snode::semantic::webHttpLog().error() << "Optaining function \"" << socketContextUpgradeFactoryFunctionName + snode::log::framework("web.http", snode::log::Boundary::Connection).error() << "Optaining function \"" << socketContextUpgradeFactoryFunctionName << "\" in plugin failed: " << core::DynamicLoader::dlError(); core::DynamicLoader::dlClose(handle); } @@ -128,18 +127,18 @@ namespace web::http { if (socketContextUpgradePlugins.contains(socketContextUpgradeName)) { socketContextUpgradeFactory = socketContextUpgradePlugins[socketContextUpgradeName].socketContextUpgradeFactory; - snode::semantic::webHttpLog().debug() << "upgrade plugin '" << socketContextUpgradeName << "' selected from dynamic cache"; + snode::log::framework("web.http", snode::log::Boundary::Connection).debug() << "upgrade plugin '" << socketContextUpgradeName << "' selected from dynamic cache"; } else if (linkedSocketContextUpgradePlugins.contains(socketContextUpgradeName)) { socketContextUpgradeFactory = linkedSocketContextUpgradePlugins[socketContextUpgradeName](); - snode::semantic::webHttpLog().debug() << "upgrade plugin '" << socketContextUpgradeName << "' selected from static cache"; + snode::log::framework("web.http", snode::log::Boundary::Connection).debug() << "upgrade plugin '" << socketContextUpgradeName << "' selected from static cache"; } else if (!onlyLinked) { socketContextUpgradeFactory = load(socketContextUpgradeName); - snode::semantic::webHttpLog().debug() + snode::log::framework("web.http", snode::log::Boundary::Connection).debug() << "upgrade plugin '" << socketContextUpgradeName << "' loaded and added to dynamic cache"; } else { - snode::semantic::webHttpLog().warn() << "upgrade plugin '" << socketContextUpgradeName << "' not found"; + snode::log::framework("web.http", snode::log::Boundary::Connection).warn() << "upgrade plugin '" << socketContextUpgradeName << "' not found"; } return socketContextUpgradeFactory; diff --git a/tests/policy/log/ParameterlessSemanticLoggerPolicyTest.cpp b/tests/policy/log/ParameterlessSemanticLoggerPolicyTest.cpp index 87b7c2471..f75cedab8 100644 --- a/tests/policy/log/ParameterlessSemanticLoggerPolicyTest.cpp +++ b/tests/policy/log/ParameterlessSemanticLoggerPolicyTest.cpp @@ -36,10 +36,10 @@ namespace { using SourceMap = std::map; constexpr std::size_t kBaselineParameterlessCallCount = 81; - constexpr std::size_t kTransferredParameterlessCallCount = 13; + constexpr std::size_t kTransferredParameterlessCallCount = 23; constexpr std::size_t kExpectedParameterlessCallCount = kBaselineParameterlessCallCount - kTransferredParameterlessCallCount; - static_assert(kExpectedParameterlessCallCount == 68); + static_assert(kExpectedParameterlessCallCount == 58); bool isIdentifierCharacter(char character) { const unsigned char value = static_cast(character); @@ -304,26 +304,7 @@ namespace { std::vector parameterlessAllowlist() { using Entry = AllowEntry; return { - // Process-wide HTTP upgrade/MIME selectors. - Entry{"src/web/http/SocketContextUpgradeFactorySelector.hpp", "webHttpLog", "SocketContextUpgradeFactory create success:", - "GLOBAL_COMPONENT_DIAGNOSTIC", "Dynamic HTTP upgrade factory selector has no connection owner."}, - Entry{"src/web/http/SocketContextUpgradeFactorySelector.hpp", "webHttpLog", "SocketContextUpgradeFactory already existing:", - "GLOBAL_COMPONENT_DIAGNOSTIC", "Dynamic HTTP upgrade factory cache diagnostic is process-wide."}, - Entry{"src/web/http/SocketContextUpgradeFactorySelector.hpp", "webHttpLog", "SocketContextUpgradeFactory create failed:", - "GLOBAL_COMPONENT_DIAGNOSTIC", "Dynamic HTTP upgrade factory load failure is process-wide."}, - Entry{"src/web/http/SocketContextUpgradeFactorySelector.hpp", "webHttpLog", "Optaining function", - "GLOBAL_COMPONENT_DIAGNOSTIC", "Dynamic HTTP upgrade symbol lookup is process-wide."}, - Entry{"src/web/http/SocketContextUpgradeFactorySelector.hpp", "webHttpLog", "selected from dynamic cache", - "GLOBAL_COMPONENT_DIAGNOSTIC", "HTTP upgrade plugin selection cache is process-wide."}, - Entry{"src/web/http/SocketContextUpgradeFactorySelector.hpp", "webHttpLog", "selected from static cache", - "GLOBAL_COMPONENT_DIAGNOSTIC", "HTTP upgrade linked-plugin selection is process-wide."}, - Entry{"src/web/http/SocketContextUpgradeFactorySelector.hpp", "webHttpLog", - "socketContextUpgradeFactory = load(socketContextUpgradeName);", - "GLOBAL_COMPONENT_DIAGNOSTIC", "HTTP upgrade dynamic cache mutation is process-wide."}, - Entry{"src/web/http/SocketContextUpgradeFactorySelector.hpp", "webHttpLog", "not found", - "GLOBAL_COMPONENT_DIAGNOSTIC", "HTTP upgrade missing-plugin decision is process-wide."}, - Entry{"src/web/http/MimeTypes.cpp", "webHttpLog", "Cannot load magic database", - "GLOBAL_COMPONENT_DIAGNOSTIC", "MIME database initialization belongs to the global HTTP component."}, + // Process-wide HTTP upgrade selectors not yet transferred to the public API. Entry{"src/web/http/client/SocketContextUpgradeFactorySelector.cpp", "httpClientUpgradeLog", "Overriding http upgrade library dir", "GLOBAL_COMPONENT_DIAGNOSTIC", "HTTP client upgrade library configuration precedes connection selection."}, @@ -453,10 +434,6 @@ namespace { "GLOBAL_COMPONENT_DIAGNOSTIC", "Subscription root belongs to the process-wide broker."}, Entry{"src/iot/mqtt/server/broker/SubscriptionTree.cpp", "mqttBrokerLog", "SubscriptionTree::TopicLevel::log() const", "GLOBAL_COMPONENT_DIAGNOSTIC", "Subscription topic level belongs to the process-wide broker."}, - - // MariaDB library initialization is process-wide. - Entry{"src/database/mariadb/MariaDBLibrary.cpp", "mariaDbLog", "mysql_library_init failed", - "GLOBAL_COMPONENT_DIAGNOSTIC", "MariaDB library initialization is a process-wide component diagnostic."}, }; } diff --git a/tests/unit/log/CMakeLists.txt b/tests/unit/log/CMakeLists.txt index 942447912..5241033a3 100644 --- a/tests/unit/log/CMakeLists.txt +++ b/tests/unit/log/CMakeLists.txt @@ -5,6 +5,10 @@ function(snodec_add_log_test test_name) set_tests_properties(${test_name} PROPERTIES LABELS "unit;log") endfunction() +snodec_add_log_test(PublicLogApiTest) +target_link_libraries(PublicLogApiTest PRIVATE snodec-test-support snodec::logger) +set_property(TEST PublicLogApiTest APPEND PROPERTY LABELS "api;format") + snodec_add_log_test(SemanticLoggerFormattingTest) target_link_libraries(SemanticLoggerFormattingTest PRIVATE snodec-test-support snodec::logger) set_property(TEST SemanticLoggerFormattingTest APPEND PROPERTY LABELS "format") diff --git a/tests/unit/log/PublicLogApiTest.cpp b/tests/unit/log/PublicLogApiTest.cpp new file mode 100644 index 000000000..801266725 --- /dev/null +++ b/tests/unit/log/PublicLogApiTest.cpp @@ -0,0 +1,49 @@ +#include "Log.h" +#include "tests/support/TestResult.h" + +#include +#include +#include + +namespace { + template + bool throwsInvalidArgument(Function&& function) { + try { + std::forward(function)(); + } catch (const std::invalid_argument&) { + return true; + } + return false; + } +} // namespace + +int main() { + tests::support::TestResult result; + + result.expectTrue(snode::log::detail::format("received {} bytes", 42) == "received 42 bytes", + "public formatter replaces placeholders"); + result.expectTrue(snode::log::detail::format("{{{}}}", "value") == "{value}", + "public formatter handles escaped braces"); + result.expectTrue(throwsInvalidArgument([] { snode::log::detail::format("{} {}"); }), + "public formatter rejects missing arguments"); + result.expectTrue(throwsInvalidArgument([] { snode::log::detail::format("literal", 1); }), + "public formatter rejects excess arguments"); + result.expectTrue(throwsInvalidArgument([] { snode::log::detail::format("{"); }), + "public formatter rejects unmatched opening braces"); + result.expectTrue(throwsInvalidArgument([] { snode::log::detail::format("}"); }), + "public formatter rejects unmatched closing braces"); + + snode::log::Scope scope{.origin = snode::log::Origin::Framework, + .boundary = snode::log::Boundary::Connection, + .component = "core.socket.stream", + .identity = {.instance = "listener", + .role = snode::log::Role::Server, + .connection = "#7"}}; + snode::log::Scope copy = scope; + scope.component.clear(); + scope.identity.instance->clear(); + result.expectTrue(copy.component == "core.socket.stream", "public scopes own component identity"); + result.expectTrue(copy.identity.instance && *copy.identity.instance == "listener", "public scopes own instance identity"); + + return result.processResult(); +}