Skip to content

Commit

Permalink
Merge pull request #140 from stevegolton/master
Browse files Browse the repository at this point in the history
Added option to prepend node name to stdout when using --disable-ui.
  • Loading branch information
xqms authored Dec 1, 2020
2 parents 273debb + 0406316 commit e5a47a3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions rosmon_core/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ void handleSignal(int)
g_shouldStop = true;
}

void logToStdout(const rosmon::LogEvent& event)
void logToStdout(const rosmon::LogEvent& event, const int max_width)
{
std::cout << event.message;
fmt::print("{:>{}}: {}", event.source, max_width, event.message);

if(!event.message.empty() && event.message.back() != '\n')
std::cout << '\n';
Expand Down Expand Up @@ -140,6 +140,18 @@ enum Action {
ACTION_LIST_ARGS,
};

static int get_max_node_name(const rosmon::monitor::Monitor &monitor)
{
std::size_t max_width = 0;

for(const auto& node : monitor.nodes())
{
max_width = std::max(max_width, node->fullName().size());
}

return max_width;
}

int main(int argc, char** argv)
{
std::string name;
Expand Down Expand Up @@ -465,7 +477,11 @@ int main(int argc, char** argv)
}
else
{
monitor.logMessageSignal.connect(logToStdout);
monitor.logMessageSignal.connect(
boost::bind(
logToStdout,
boost::placeholders::_1,
get_max_node_name(monitor)));
}

// ROS interface
Expand Down

0 comments on commit e5a47a3

Please sign in to comment.