Ask Your Question
3

Trigger code segments for ROS_DEBUG only

asked 2011-08-22 05:08:13 -0500

egiljones gravatar image

I'm wondering if there's a way to do the following in C++:

if(<my logger level is set to ROS_DEBUG>) 
{
  //execute a costly code block that I don't want to do for the sake of efficiency
  //unless my logger level is set to ROS_DEBUG.  
  ROS_DEBUG_STREAM("Some output based on the computation");
}

I need to do some computation to get useful output in DEBUG mode, but I don't want to do that computation in normal operation.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2011-08-22 08:35:07 -0500

tfoote gravatar image

This is a little bit of a hack but would have the desired effect.

string costly_method_wrapper()
{
//Costly stuff in here
return std::string(); // or real debugging info here.
}
ROS_DEBUG_STREAM("my output is " << costly_method_wrapper() << " other debug info");
edit flag offensive delete link more

Comments

I was hoping for something slightly more elegant, but this indeed will do.
egiljones gravatar image egiljones  ( 2011-08-24 05:57:56 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-08-22 05:08:13 -0500

Seen: 552 times

Last updated: Aug 22 '11