Skip to content

Commit d7269f1

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

File tree

1 file changed

+40
-31
lines changed

1 file changed

+40
-31
lines changed

tools/ddsrouter_tool/src/cpp/main.cpp

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <cpp_utils/time/time_utils.hpp>
2929
#include <cpp_utils/utils.hpp>
3030

31+
#include <ddspipe_core/configuration/DdsPipeLogConfiguration.hpp>
3132
#include <ddspipe_core/logging/DdsLogConsumer.hpp>
3233
#include <ddspipe_core/monitoring/Monitor.hpp>
3334
#include <ddspipe_core/monitoring/producers/TopicsMonitorProducer.hpp>
@@ -47,6 +48,7 @@ using namespace eprosima;
4748
using namespace eprosima::ddsrouter;
4849

4950
int exit(const ui::ProcessReturnCode& code);
51+
void register_log_consumers(const ddspipe::core::DdsPipeLogConfiguration& configuration);
5052

5153
int main(
5254
int argc,
@@ -120,6 +122,12 @@ int main(
120122
commandline_args.timeout));
121123
}
122124

125+
// Register the LogConsumers with the CommandLine configuration to log the YAML configuration errors.
126+
ddspipe::core::DdsPipeLogConfiguration log_configuration;
127+
log_configuration.set(utils::VerbosityKind::Warning);
128+
129+
register_log_consumers(log_configuration);
130+
123131
/////
124132
// DDS Router Initialization
125133

@@ -128,37 +136,8 @@ int main(
128136
yaml::YamlReaderConfiguration::load_ddsrouter_configuration_from_file(commandline_args.file_path,
129137
&commandline_args);
130138

131-
// Debug
132-
{
133-
const auto log_configuration = router_configuration.ddspipe_configuration.log_configuration;
134-
135-
// Remove every consumer
136-
eprosima::utils::Log::ClearConsumers();
137-
138-
// Activate log with verbosity, as this will avoid running log thread with not desired kind
139-
eprosima::utils::Log::SetVerbosity(log_configuration.verbosity);
140-
141-
// Stdout Log Consumer
142-
if (log_configuration.stdout_enable)
143-
{
144-
eprosima::utils::Log::RegisterConsumer(
145-
std::make_unique<eprosima::utils::StdLogConsumer>(&log_configuration));
146-
}
147-
148-
// DDS Log Consumer
149-
if (log_configuration.publish.enable)
150-
{
151-
eprosima::utils::Log::RegisterConsumer(
152-
std::make_unique<eprosima::ddspipe::core::DdsLogConsumer>(&log_configuration));
153-
}
154-
155-
// NOTE:
156-
// It will not filter any log, so Fast DDS logs will be visible unless Fast DDS is compiled
157-
// in non debug or with LOG_NO_INFO=ON.
158-
// This is the easiest way to allow to see Warnings and Errors from Fast DDS.
159-
// Change it when Log Module is independent and with more extensive API.
160-
// eprosima::utils::Log::SetCategoryFilter(std::regex("(DDSROUTER)"));
161-
}
139+
// Register the LogConsumers with their actual configuration
140+
register_log_consumers(router_configuration.ddspipe_configuration.log_configuration);
162141

163142
// Load XML profiles
164143
ddspipe::participants::XmlHandler::load_xml(router_configuration.xml_configuration);
@@ -301,3 +280,33 @@ int exit(const ui::ProcessReturnCode& code)
301280

302281
return static_cast<int>(code);
303282
}
283+
284+
void register_log_consumers(const ddspipe::core::DdsPipeLogConfiguration& configuration)
285+
{
286+
// Remove every consumer
287+
utils::Log::ClearConsumers();
288+
289+
// Activate log with verbosity, as this will avoid running log thread with not desired kind
290+
utils::Log::SetVerbosity(configuration.verbosity);
291+
292+
// Stdout Log Consumer
293+
if (configuration.stdout_enable)
294+
{
295+
utils::Log::RegisterConsumer(
296+
std::make_unique<utils::StdLogConsumer>(&configuration));
297+
}
298+
299+
// DDS Log Consumer
300+
if (configuration.publish.enable)
301+
{
302+
utils::Log::RegisterConsumer(
303+
std::make_unique<ddspipe::core::DdsLogConsumer>(&configuration));
304+
}
305+
306+
// NOTE:
307+
// It will not filter any log, so Fast DDS logs will be visible unless Fast DDS is compiled
308+
// in non debug or with LOG_NO_INFO=ON.
309+
// This is the easiest way to allow to see Warnings and Errors from Fast DDS.
310+
// Change it when Log Module is independent and with more extensive API.
311+
// utils::Log::SetCategoryFilter(std::regex("(DDSROUTER)"));
312+
}

0 commit comments

Comments
 (0)