Configuring the debugging level of a particular node

By default, only messages of INFO or higher levels are shown. ROS uses these levels to filter the messages printed by a particular node. There are many ways to do so. Some of them are set at the time of compilation and some messages aren't even compiled below a given verbosity level; others can be changed before execution using a configuration file, and it is also possible to change the logging level dynamically using the rqt_console and rqt_logger_level tools.

It is possible to set the logging level at compile time in our source code, but this is very uncommon and not recommended as it it requires us to modify the source code to change the logging level.

Nevertheless, in some cases we need to remove the overhead of all the logging functions below a given level. In those cases, we won't be able to see those messages later because they get removed from the code and are not simply disabled. To do so, we must set ROSCONSOLE_MIN_SEVERITY to the minimum severity level desired, or even none, in order to avoid any message (even FATAL). The macros are as follows:

ROSCONSOLE_SEVERITY_DEBUG 
ROSCONSOLE_SEVERITY_INFO 
ROSCONSOLE_SEVERITY_WARN 
ROSCONSOLE_SEVERITY_ERROR 
ROSCONSOLE_SEVERITY_FATAL 
ROSCONSOLE_SEVERITY_NONE 

The ROSCONSOLE_MIN_SEVERITY macro is defined in <ros/console.h> to the DEBUG level if not given. Therefore, we can pass it as a build argument (with -D) or put it before all the headers. For example, to show only ERROR (or higher) messages, we will put this in our source code:

#define ROSCONSOLE_MIN_SEVERITY ROSCONSOLE_SEVERITY_ERROR 

Alternatively, we can set this to all the nodes in a package, setting this macro in CMakeLists.txt by adding this line:

add_definitions(-DROSCONSOLE_MIN_SEVERITY 
=ROSCONSOLE_SEVERITY_ERROR)

On the other hand, we have the more flexible solution of setting the minimum logging level in a configuration file. We create a config folder with a file, such as chapter3_tutorials.config, and this content (edit the file provided since it is set to DEBUG):

log4j.logger.ros.chapter3_tutorials=ERROR 

Then, we must set the ROSCONSOLE_CONFIG_FILE environment variable to point to our file. We can do this on a launch file that also runs the node. Therefore, we will extend the launch file shown earlier to do so with the env (environment variable) element, as shown here:

<launch> 
  <!-- Logger config --> 
  <env name="ROSCONSOLE_CONFIG_FILE" 
  value="$(find 
chapter3_tutorials)/config/chapter3_tutorials.config"/> <!-- Example 1 --> <node pkg="chapter3_tutorials" type="example1" name="example1" output="screen"/> </launch>

The environment variable takes the configuration file shown previously, which contains the logging level specification for each named logger; in this case, it is for the package name.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.173.227