Skip to content
Snippets Groups Projects
Unverified Commit 8e2eaadb authored by zenker's avatar zenker Committed by GitHub
Browse files

Handle write calls without a message

If someone includes the Logger into an ApplcationModule and calls writeAll() the Logger variable message will be written. To catch that cases set message empty after calling sendMessage and ignore empty messages in the LoggingModule.
parent 103f7ea9
No related branches found
No related tags found
No related merge requests found
......@@ -55,6 +55,8 @@ void Logger::sendMessage(const std::string& msg, const logging::LogLevel& level)
}
message = std::to_string(level) + msg + "\n";
message.write();
// set emtpy message to let the LoggingModule know that someone called writeAll() without sending a message
message = "";
}
else {
// only use the buffer until ctk initialized the process variables
......@@ -108,16 +110,16 @@ void LoggingModule::mainLoop() {
id_list[module->msg.getId()] = &(*module);
}
auto group = readAnyGroup();
std::string msg;
MessageSource* currentSender;
LogLevel level;
while(1) {
auto id = group.readAny();
if(id_list.count(id) == 0){
throw ChimeraTK::logic_error("Cannot find element id"
"when updating logging variables.");
}
std::string msg;
MessageSource* currentSender;
LogLevel level;
try{
currentSender = id_list.at(id);
msg = (std::string)(currentSender->msg);
......@@ -125,6 +127,10 @@ void LoggingModule::mainLoop() {
throw ChimeraTK::logic_error("Cannot find element id"
"when updating logging variables.");
}
// if message is empty assume someone called writeAll() in a module containing the Logger -> ignore
if(msg.empty()){
continue;
}
try{
level = static_cast<LogLevel>(std::strtoul(&msg.at(0),NULL, 0));
} catch (std::out_of_range &e){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment