From 85a520169e66f6024ba4d14be83a1ea08890adce Mon Sep 17 00:00:00 2001 From: tempate Date: Tue, 20 Feb 2024 11:03:00 +0100 Subject: [PATCH 1/8] Register a DdsLogConsumer to publish the logs Signed-off-by: tempate --- .../configuration/SpecsConfiguration.hpp | 6 +++--- ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp | 2 +- tools/ddsrouter_tool/src/cpp/main.cpp | 11 ++++++++--- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp index 85d5adbf6..72ca262f4 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp @@ -18,9 +18,9 @@ #include #include -#include #include +#include #include #include @@ -72,8 +72,8 @@ struct SpecsConfiguration : public ddspipe::core::IConfiguration //! The type of the entities whose discovery triggers the discovery callbacks. ddspipe::core::DiscoveryTrigger discovery_trigger = ddspipe::core::DiscoveryTrigger::READER; - //! Configuration of the CustomStdLogConsumer. - utils::LogConfiguration log_configuration; + //! Configuration of the DdsLogConsumer. + ddspipe::core::DdsPipeLogConfiguration log_configuration; }; } /* namespace core */ diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp index b2fe694ff..26d4105ef 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -82,7 +82,7 @@ void YamlReader::fill( // Get optional Log Configuration if (YamlReader::is_tag_present(yml, LOG_CONFIGURATION_TAG)) { - object.log_configuration = YamlReader::get(yml, LOG_CONFIGURATION_TAG, version); + object.log_configuration = YamlReader::get(yml, LOG_CONFIGURATION_TAG, version); } } diff --git a/tools/ddsrouter_tool/src/cpp/main.cpp b/tools/ddsrouter_tool/src/cpp/main.cpp index 1f4d7d9b4..b4b9c6c90 100644 --- a/tools/ddsrouter_tool/src/cpp/main.cpp +++ b/tools/ddsrouter_tool/src/cpp/main.cpp @@ -29,6 +29,8 @@ #include #include +#include + #include #include @@ -90,7 +92,6 @@ int main( logUser(DDSROUTER_EXECUTION, "Starting DDS Router Tool execution."); - // Encapsulating execution in block to erase all memory correctly before closing process try { @@ -132,9 +133,13 @@ int main( // Activate log with verbosity, as this will avoid running log thread with not desired kind eprosima::utils::Log::SetVerbosity(router_configuration.ddspipe_configuration.log_configuration.verbosity); - eprosima::utils::LogConfiguration log_config = router_configuration.ddspipe_configuration.log_configuration; + const auto log_configuration = router_configuration.ddspipe_configuration.log_configuration; + + eprosima::utils::Log::RegisterConsumer( + std::make_unique(&log_configuration)); + eprosima::utils::Log::RegisterConsumer( - std::make_unique(&log_config)); + std::make_unique(log_configuration)); // NOTE: // It will not filter any log, so Fast DDS logs will be visible unless Fast DDS is compiled From be90f14f6441f7f696bf0f13648b5328f0f6e48e Mon Sep 17 00:00:00 2001 From: tempate Date: Thu, 29 Feb 2024 07:39:11 +0100 Subject: [PATCH 2/8] Apply suggestions Signed-off-by: tempate --- .../configuration/SpecsConfiguration.hpp | 4 ++-- .../src/cpp/YamlReader_configuration.cpp | 2 +- tools/ddsrouter_tool/src/cpp/main.cpp | 20 +++++++++++++------ 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp index 72ca262f4..5921e5322 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -73,7 +73,7 @@ struct SpecsConfiguration : public ddspipe::core::IConfiguration ddspipe::core::DiscoveryTrigger discovery_trigger = ddspipe::core::DiscoveryTrigger::READER; //! Configuration of the DdsLogConsumer. - ddspipe::core::DdsPipeLogConfiguration log_configuration; + ddspipe::core::DdsLogConfiguration log_configuration; }; } /* namespace core */ diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp index 26d4105ef..19d8f97d6 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -82,7 +82,7 @@ void YamlReader::fill( // Get optional Log Configuration if (YamlReader::is_tag_present(yml, LOG_CONFIGURATION_TAG)) { - object.log_configuration = YamlReader::get(yml, LOG_CONFIGURATION_TAG, version); + object.log_configuration = YamlReader::get(yml, LOG_CONFIGURATION_TAG, version); } } diff --git a/tools/ddsrouter_tool/src/cpp/main.cpp b/tools/ddsrouter_tool/src/cpp/main.cpp index b4b9c6c90..a314e49ba 100644 --- a/tools/ddsrouter_tool/src/cpp/main.cpp +++ b/tools/ddsrouter_tool/src/cpp/main.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -135,11 +135,19 @@ int main( const auto log_configuration = router_configuration.ddspipe_configuration.log_configuration; - eprosima::utils::Log::RegisterConsumer( - std::make_unique(&log_configuration)); - - eprosima::utils::Log::RegisterConsumer( - std::make_unique(log_configuration)); + // Stdout Log Consumer + if (log_configuration.stdout_enable) + { + eprosima::utils::Log::RegisterConsumer( + std::make_unique(&log_configuration)); + } + + // DDS Log Consumer + if (log_configuration.publish.enable) + { + eprosima::utils::Log::RegisterConsumer( + std::make_unique(log_configuration)); + } // NOTE: // It will not filter any log, so Fast DDS logs will be visible unless Fast DDS is compiled From 258d88342696d63bc81bb36d531b3ca68400c527 Mon Sep 17 00:00:00 2001 From: tempate Date: Thu, 29 Feb 2024 15:33:19 +0100 Subject: [PATCH 3/8] Minor changes Signed-off-by: tempate --- .../ddsrouter_core/configuration/SpecsConfiguration.hpp | 6 +++--- ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp | 2 +- tools/ddsrouter_tool/src/cpp/main.cpp | 9 ++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp index 5921e5322..a7dce6e24 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp @@ -20,7 +20,7 @@ #include #include -#include +#include #include #include @@ -72,8 +72,8 @@ struct SpecsConfiguration : public ddspipe::core::IConfiguration //! The type of the entities whose discovery triggers the discovery callbacks. ddspipe::core::DiscoveryTrigger discovery_trigger = ddspipe::core::DiscoveryTrigger::READER; - //! Configuration of the DdsLogConsumer. - ddspipe::core::DdsLogConfiguration log_configuration; + //! Configuration of the StdLogConsumer and the DdsLogConsumer. + ddspipe::core::DdsPipeLogConfiguration log_configuration; }; } /* namespace core */ diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp index 19d8f97d6..26d4105ef 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -82,7 +82,7 @@ void YamlReader::fill( // Get optional Log Configuration if (YamlReader::is_tag_present(yml, LOG_CONFIGURATION_TAG)) { - object.log_configuration = YamlReader::get(yml, LOG_CONFIGURATION_TAG, version); + object.log_configuration = YamlReader::get(yml, LOG_CONFIGURATION_TAG, version); } } diff --git a/tools/ddsrouter_tool/src/cpp/main.cpp b/tools/ddsrouter_tool/src/cpp/main.cpp index a314e49ba..1baff7213 100644 --- a/tools/ddsrouter_tool/src/cpp/main.cpp +++ b/tools/ddsrouter_tool/src/cpp/main.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include @@ -127,13 +126,13 @@ int main( // Debug { + const auto log_configuration = router_configuration.ddspipe_configuration.log_configuration; + // Remove every consumer eprosima::utils::Log::ClearConsumers(); // Activate log with verbosity, as this will avoid running log thread with not desired kind - eprosima::utils::Log::SetVerbosity(router_configuration.ddspipe_configuration.log_configuration.verbosity); - - const auto log_configuration = router_configuration.ddspipe_configuration.log_configuration; + eprosima::utils::Log::SetVerbosity(log_configuration.verbosity); // Stdout Log Consumer if (log_configuration.stdout_enable) @@ -146,7 +145,7 @@ int main( if (log_configuration.publish.enable) { eprosima::utils::Log::RegisterConsumer( - std::make_unique(log_configuration)); + std::make_unique(&log_configuration)); } // NOTE: From 55bd32b3b2c651557904cc132f0c2f8b012d929e Mon Sep 17 00:00:00 2001 From: tempate Date: Fri, 1 Mar 2024 10:15:42 +0100 Subject: [PATCH 4/8] Apply self-suggestions Signed-off-by: tempate --- .../include/ddsrouter_core/configuration/SpecsConfiguration.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp index a7dce6e24..5ea94e58a 100644 --- a/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp +++ b/ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp @@ -72,7 +72,7 @@ struct SpecsConfiguration : public ddspipe::core::IConfiguration //! The type of the entities whose discovery triggers the discovery callbacks. ddspipe::core::DiscoveryTrigger discovery_trigger = ddspipe::core::DiscoveryTrigger::READER; - //! Configuration of the StdLogConsumer and the DdsLogConsumer. + //! Configuration of the DDS Pipe's Log consumers. ddspipe::core::DdsPipeLogConfiguration log_configuration; }; From 0145fb510667470b7b26d86b829954ff0917ae0a Mon Sep 17 00:00:00 2001 From: tempate Date: Fri, 1 Mar 2024 12:00:37 +0100 Subject: [PATCH 5/8] Documentation Signed-off-by: tempate --- docs/rst/user_manual/configuration.rst | 56 ++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/docs/rst/user_manual/configuration.rst b/docs/rst/user_manual/configuration.rst index 1a808cbea..9b4f6c6cf 100644 --- a/docs/rst/user_manual/configuration.rst +++ b/docs/rst/user_manual/configuration.rst @@ -444,6 +444,54 @@ By default, the filter allows all errors to be displayed, while selectively perm For the logs to function properly, the ``-DLOG_INFO=ON`` compilation flag is required. +By default, the logs will be printed in the standard output. +To publish the logs, under the tag ``publish``, set ``enable: true`` and set a ``domain`` and a ``topic-name``. +The type of the logs published is defined as follows: + +**LogEntry.idl** + +.. code-block:: idl + + const long UNDEFINED = 0x10000000; + const long SAMPLE_LOST = 0x10000001; + const long TOPIC_MISMATCH_TYPE = 0x10000002; + const long TOPIC_MISMATCH_QOS = 0x10000003; + + enum Kind { + Info, + Warning, + Error + }; + + struct LogEntry { + @key long event; + Kind kind; + string category; + string message; + string timestamp; + }; + +.. note:: + + The type of the logs can be published by setting ``publish-type: true``. + +**Example of usage** + +.. code-block:: yaml + + logging: + verbosity: info + filter: + error: "DDSPIPE|DDSROUTER" + warning: "DDSPIPE|DDSROUTER" + info: "DDSROUTER" + publish: + enable: true + domain: 84 + topic-name: "DdsRouterLogs" + publish-type: false + stdout: true + Participant Configuration ========================= @@ -879,17 +927,25 @@ A complete example of all the configurations described on this page can be found threads: 10 remove-unused-entities: false discovery-trigger: reader + qos: history-depth: 1000 max-tx-rate: 0 max-rx-rate: 20 downsampling: 3 + logging: verbosity: info filter: error: "DDSPIPE|DDSROUTER" warning: "DDSPIPE|DDSROUTER" info: "DDSROUTER" + publish: + enable: true + domain: 84 + topic-name: "DdsRouterLogs" + publish-type: false + stdout: true # XML configurations to load xml: From ff46fd1fae7d40ea38331897f859338391933271 Mon Sep 17 00:00:00 2001 From: tempate Date: Tue, 5 Mar 2024 11:38:53 +0100 Subject: [PATCH 6/8] Apply suggestions Signed-off-by: tempate --- docs/rst/user_manual/configuration.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/rst/user_manual/configuration.rst b/docs/rst/user_manual/configuration.rst index 9b4f6c6cf..9da144832 100644 --- a/docs/rst/user_manual/configuration.rst +++ b/docs/rst/user_manual/configuration.rst @@ -444,7 +444,8 @@ By default, the filter allows all errors to be displayed, while selectively perm For the logs to function properly, the ``-DLOG_INFO=ON`` compilation flag is required. -By default, the logs will be printed in the standard output. +The |ddsrouter| prints the logs by default (warnings and errors in the standard error and infos in the standard output). +The |ddsrouter|, however, can also publish the logs in a DDS topic. To publish the logs, under the tag ``publish``, set ``enable: true`` and set a ``domain`` and a ``topic-name``. The type of the logs published is defined as follows: From 2f5d4e28bd4734c6d34d6fbc189c314e95cbe87b Mon Sep 17 00:00:00 2001 From: tempate Date: Tue, 5 Mar 2024 13:02:12 +0100 Subject: [PATCH 7/8] Delete the log consumers before closing Signed-off-by: tempate --- tools/ddsrouter_tool/src/cpp/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/ddsrouter_tool/src/cpp/main.cpp b/tools/ddsrouter_tool/src/cpp/main.cpp index 1baff7213..9a65d9fe3 100644 --- a/tools/ddsrouter_tool/src/cpp/main.cpp +++ b/tools/ddsrouter_tool/src/cpp/main.cpp @@ -279,5 +279,8 @@ int main( // Force print every log before closing eprosima::utils::Log::Flush(); + // Delete the consumers before closing + eprosima::utils::Log::ClearConsumers(); + return static_cast(ui::ProcessReturnCode::success); } From 76baa58279b123cea95c4668fe01b1e5fb08201e Mon Sep 17 00:00:00 2001 From: tempate Date: Wed, 6 Mar 2024 10:23:54 +0100 Subject: [PATCH 8/8] Uncrustify Signed-off-by: tempate --- ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp index 26d4105ef..1c3a8b8a8 100644 --- a/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp +++ b/ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp @@ -82,7 +82,8 @@ void YamlReader::fill( // Get optional Log Configuration if (YamlReader::is_tag_present(yml, LOG_CONFIGURATION_TAG)) { - object.log_configuration = YamlReader::get(yml, LOG_CONFIGURATION_TAG, version); + object.log_configuration = YamlReader::get(yml, LOG_CONFIGURATION_TAG, + version); } }