Use ROS_ macro to output std::vector data
If I'm dealing with std::vector
data in C++ and I'd like to print it on the output stream (e.g. for debugging), I'm going to do something like this:
std::cout << "Data Retrieved: \n";
std::copy(data.begin(), data.end(), std::ostream_iterator<double>(std::cout, " "));
std::cout << std::endl;
How to reproduce this behaviour using (for example) ROS_DEBUG_STREAM()
macro?
I wish to include logger level also in the output of vector data.
The only way I found to achieve this result is something as follows:
log4cxx::LoggerPtr logger = log4cxx::Logger::getLogger(ROSCONSOLE_DEFAULT_NAME);
if (logger && logger->getLevel() == log4cxx::Level::getDebug()) {
// debugging code
std::cout << "Data Retrieved: \n";
std::copy(data.begin(), data.end(), std::ostream_iterator<double>(std::cout, " "));
std::cout << std::endl;
}
In which case I need to link the proper library:
find_library(LOG4CXX_LIBRARY log4cxx)
target_link_libraries(some_target ${LOG4CXX_LIBRARY})
(I found these useful info here)
Someone knows if there is a better way? Thank you!