Skip to content

Commit 612ef25

Browse files
tempateLuciaEchevarria99
tempate
authored andcommitted
Register a temporary log consumer to log warnings while parsing the YAML
Signed-off-by: tempate <[email protected]>
1 parent 9ee5976 commit 612ef25

File tree

1 file changed

+40
-31
lines changed

1 file changed

+40
-31
lines changed

fastddsspy_tool/src/cpp/main.cpp

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <cpp_utils/types/Fuzzy.hpp>
3131
#include <cpp_utils/utils.hpp>
3232

33+
#include <ddspipe_core/configuration/DdsPipeLogConfiguration.hpp>
3334
#include <ddspipe_core/core/DdsPipe.hpp>
3435
#include <ddspipe_core/dynamic/ParticipantsDatabase.hpp>
3536
#include <ddspipe_core/dynamic/DiscoveryDatabase.hpp>
@@ -49,6 +50,7 @@
4950

5051

5152
int exit(const eprosima::spy::ProcessReturnCode& code);
53+
void register_log_consumers(const eprosima::ddspipe::core::DdsPipeLogConfiguration& configuration);
5254

5355

5456
int main(
@@ -99,6 +101,12 @@ int main(
99101
// Encapsulating execution in block to erase all memory correctly before closing process
100102
try
101103
{
104+
// Register the LogConsumers to log the YAML configuration errors
105+
eprosima::ddspipe::core::DdsPipeLogConfiguration log_configuration;
106+
log_configuration.set(eprosima::utils::VerbosityKind::Warning);
107+
108+
register_log_consumers(log_configuration);
109+
102110
/////
103111
// Fast DDS Spy Initialization
104112

@@ -113,37 +121,8 @@ int main(
113121
eprosima::spy::yaml::Configuration configuration = eprosima::spy::yaml::Configuration(
114122
commandline_args.file_path, &commandline_args);
115123

116-
// Debug
117-
{
118-
const auto log_configuration = configuration.ddspipe_configuration.log_configuration;
119-
120-
// Remove every consumer
121-
eprosima::utils::Log::ClearConsumers();
122-
123-
// Activate log with verbosity, as this will avoid running log thread with not desired kind
124-
eprosima::utils::Log::SetVerbosity(configuration.ddspipe_configuration.log_configuration.verbosity);
125-
126-
// Stdout Log Consumer
127-
if (log_configuration.stdout_enable)
128-
{
129-
eprosima::utils::Log::RegisterConsumer(
130-
std::make_unique<eprosima::utils::StdLogConsumer>(&log_configuration));
131-
}
132-
133-
// DDS Log Consumer
134-
if (log_configuration.publish.enable)
135-
{
136-
eprosima::utils::Log::RegisterConsumer(
137-
std::make_unique<eprosima::ddspipe::core::DdsLogConsumer>(&log_configuration));
138-
}
139-
140-
// NOTE:
141-
// It will not filter any log, so Fast DDS logs will be visible unless Fast DDS is compiled
142-
// in non debug or with LOG_NO_INFO=ON.
143-
// This is the easiest way to allow to see Warnings and Errors from Fast DDS.
144-
// Change it when Log Module is independent and with more extensive API.
145-
// eprosima::utils::Log::SetCategoryFilter(std::regex("(ddspipe|FASTDDSSPY)"));
146-
}
124+
register_log_consumers(configuration.ddspipe_configuration.log_configuration);
125+
147126
// Create the Spy
148127
eprosima::spy::Controller spy(configuration);
149128

@@ -260,3 +239,33 @@ int exit(const eprosima::spy::ProcessReturnCode& code)
260239

261240
return static_cast<int>(code);
262241
}
242+
243+
void register_log_consumers(const eprosima::ddspipe::core::DdsPipeLogConfiguration& configuration)
244+
{
245+
// Remove every consumer
246+
eprosima::utils::Log::ClearConsumers();
247+
248+
// Activate log with verbosity, as this will avoid running log thread with not desired kind
249+
eprosima::utils::Log::SetVerbosity(configuration.verbosity);
250+
251+
// Stdout Log Consumer
252+
if (configuration.stdout_enable)
253+
{
254+
eprosima::utils::Log::RegisterConsumer(
255+
std::make_unique<eprosima::utils::StdLogConsumer>(&configuration));
256+
}
257+
258+
// DDS Log Consumer
259+
if (configuration.publish.enable)
260+
{
261+
eprosima::utils::Log::RegisterConsumer(
262+
std::make_unique<eprosima::ddspipe::core::DdsLogConsumer>(&configuration));
263+
}
264+
265+
// NOTE:
266+
// It will not filter any log, so Fast DDS logs will be visible unless Fast DDS is compiled
267+
// in non debug or with LOG_NO_INFO=ON.
268+
// This is the easiest way to allow to see Warnings and Errors from Fast DDS.
269+
// Change it when Log Module is independent and with more extensive API.
270+
// utils::Log::SetCategoryFilter(std::regex("(FASTDDSSPY)"));
271+
}

0 commit comments

Comments
 (0)