Skip to content

Commit 29de75f

Browse files
authored
Publish Fast-DDS's Logs (#436)
* Register a DdsLogConsumer to publish the logs Signed-off-by: tempate <danieldiaz@eprosima.com> * Apply suggestions Signed-off-by: tempate <danieldiaz@eprosima.com> * Minor changes Signed-off-by: tempate <danieldiaz@eprosima.com> * Apply self-suggestions Signed-off-by: tempate <danieldiaz@eprosima.com> * Documentation Signed-off-by: tempate <danieldiaz@eprosima.com> * Apply suggestions Signed-off-by: tempate <danieldiaz@eprosima.com> * Delete the log consumers before closing Signed-off-by: tempate <danieldiaz@eprosima.com> * Uncrustify Signed-off-by: tempate <danieldiaz@eprosima.com> --------- Signed-off-by: tempate <danieldiaz@eprosima.com>
1 parent bd58ccf commit 29de75f

4 files changed

Lines changed: 85 additions & 12 deletions

File tree

ddsrouter_core/include/ddsrouter_core/configuration/SpecsConfiguration.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#include <set>
1919

2020
#include <cpp_utils/Formatter.hpp>
21-
#include <cpp_utils/logging/LogConfiguration.hpp>
2221

2322
#include <ddspipe_core/configuration/DdsPipeConfiguration.hpp>
23+
#include <ddspipe_core/configuration/DdsPipeLogConfiguration.hpp>
2424
#include <ddspipe_core/configuration/IConfiguration.hpp>
2525
#include <ddspipe_core/types/dds/TopicQoS.hpp>
2626

@@ -72,8 +72,8 @@ struct SpecsConfiguration : public ddspipe::core::IConfiguration
7272
//! The type of the entities whose discovery triggers the discovery callbacks.
7373
ddspipe::core::DiscoveryTrigger discovery_trigger = ddspipe::core::DiscoveryTrigger::READER;
7474

75-
//! Configuration of the CustomStdLogConsumer.
76-
utils::LogConfiguration log_configuration;
75+
//! Configuration of the DDS Pipe's Log consumers.
76+
ddspipe::core::DdsPipeLogConfiguration log_configuration;
7777
};
7878

7979
} /* namespace core */

ddsrouter_yaml/src/cpp/YamlReader_configuration.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ void YamlReader::fill(
8282
// Get optional Log Configuration
8383
if (YamlReader::is_tag_present(yml, LOG_CONFIGURATION_TAG))
8484
{
85-
object.log_configuration = YamlReader::get<utils::LogConfiguration>(yml, LOG_CONFIGURATION_TAG, version);
85+
object.log_configuration = YamlReader::get<ddspipe::core::DdsPipeLogConfiguration>(yml, LOG_CONFIGURATION_TAG,
86+
version);
8687
}
8788
}
8889

docs/rst/user_manual/configuration.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,55 @@ By default, the filter allows all errors to be displayed, while selectively perm
444444

445445
For the logs to function properly, the ``-DLOG_INFO=ON`` compilation flag is required.
446446

447+
The |ddsrouter| prints the logs by default (warnings and errors in the standard error and infos in the standard output).
448+
The |ddsrouter|, however, can also publish the logs in a DDS topic.
449+
To publish the logs, under the tag ``publish``, set ``enable: true`` and set a ``domain`` and a ``topic-name``.
450+
The type of the logs published is defined as follows:
451+
452+
**LogEntry.idl**
453+
454+
.. code-block:: idl
455+
456+
const long UNDEFINED = 0x10000000;
457+
const long SAMPLE_LOST = 0x10000001;
458+
const long TOPIC_MISMATCH_TYPE = 0x10000002;
459+
const long TOPIC_MISMATCH_QOS = 0x10000003;
460+
461+
enum Kind {
462+
Info,
463+
Warning,
464+
Error
465+
};
466+
467+
struct LogEntry {
468+
@key long event;
469+
Kind kind;
470+
string category;
471+
string message;
472+
string timestamp;
473+
};
474+
475+
.. note::
476+
477+
The type of the logs can be published by setting ``publish-type: true``.
478+
479+
**Example of usage**
480+
481+
.. code-block:: yaml
482+
483+
logging:
484+
verbosity: info
485+
filter:
486+
error: "DDSPIPE|DDSROUTER"
487+
warning: "DDSPIPE|DDSROUTER"
488+
info: "DDSROUTER"
489+
publish:
490+
enable: true
491+
domain: 84
492+
topic-name: "DdsRouterLogs"
493+
publish-type: false
494+
stdout: true
495+
447496
Participant Configuration
448497
=========================
449498

@@ -879,17 +928,25 @@ A complete example of all the configurations described on this page can be found
879928
threads: 10
880929
remove-unused-entities: false
881930
discovery-trigger: reader
931+
882932
qos:
883933
history-depth: 1000
884934
max-tx-rate: 0
885935
max-rx-rate: 20
886936
downsampling: 3
937+
887938
logging:
888939
verbosity: info
889940
filter:
890941
error: "DDSPIPE|DDSROUTER"
891942
warning: "DDSPIPE|DDSROUTER"
892943
info: "DDSROUTER"
944+
publish:
945+
enable: true
946+
domain: 84
947+
topic-name: "DdsRouterLogs"
948+
publish-type: false
949+
stdout: true
893950
894951
# XML configurations to load
895952
xml:

tools/ddsrouter_tool/src/cpp/main.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
#include <cpp_utils/event/SignalEventHandler.hpp>
2424
#include <cpp_utils/exception/ConfigurationException.hpp>
2525
#include <cpp_utils/exception/InitializationException.hpp>
26-
#include <cpp_utils/logging/CustomStdLogConsumer.hpp>
27-
#include <cpp_utils/logging/LogConfiguration.hpp>
26+
#include <cpp_utils/logging/StdLogConsumer.hpp>
2827
#include <cpp_utils/ReturnCode.hpp>
2928
#include <cpp_utils/time/time_utils.hpp>
3029
#include <cpp_utils/utils.hpp>
3130

31+
#include <ddspipe_core/logging/DdsLogConsumer.hpp>
32+
3233
#include <ddspipe_participants/xml/XmlHandler.hpp>
3334

3435
#include <ddsrouter_core/configuration/DdsRouterConfiguration.hpp>
@@ -90,7 +91,6 @@ int main(
9091

9192
logUser(DDSROUTER_EXECUTION, "Starting DDS Router Tool execution.");
9293

93-
9494
// Encapsulating execution in block to erase all memory correctly before closing process
9595
try
9696
{
@@ -126,15 +126,27 @@ int main(
126126

127127
// Debug
128128
{
129+
const auto log_configuration = router_configuration.ddspipe_configuration.log_configuration;
130+
129131
// Remove every consumer
130132
eprosima::utils::Log::ClearConsumers();
131133

132134
// Activate log with verbosity, as this will avoid running log thread with not desired kind
133-
eprosima::utils::Log::SetVerbosity(router_configuration.ddspipe_configuration.log_configuration.verbosity);
134-
135-
eprosima::utils::LogConfiguration log_config = router_configuration.ddspipe_configuration.log_configuration;
136-
eprosima::utils::Log::RegisterConsumer(
137-
std::make_unique<eprosima::utils::CustomStdLogConsumer>(&log_config));
135+
eprosima::utils::Log::SetVerbosity(log_configuration.verbosity);
136+
137+
// Stdout Log Consumer
138+
if (log_configuration.stdout_enable)
139+
{
140+
eprosima::utils::Log::RegisterConsumer(
141+
std::make_unique<eprosima::utils::StdLogConsumer>(&log_configuration));
142+
}
143+
144+
// DDS Log Consumer
145+
if (log_configuration.publish.enable)
146+
{
147+
eprosima::utils::Log::RegisterConsumer(
148+
std::make_unique<eprosima::ddspipe::core::DdsLogConsumer>(&log_configuration));
149+
}
138150

139151
// NOTE:
140152
// It will not filter any log, so Fast DDS logs will be visible unless Fast DDS is compiled
@@ -267,5 +279,8 @@ int main(
267279
// Force print every log before closing
268280
eprosima::utils::Log::Flush();
269281

282+
// Delete the consumers before closing
283+
eprosima::utils::Log::ClearConsumers();
284+
270285
return static_cast<int>(ui::ProcessReturnCode::success);
271286
}

0 commit comments

Comments
 (0)