Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

ROS Logging (roscpp and rospy) functionality allows for setting the verbosity of programs at run time through the rosconsole interface.  The logging level specifies how verbose a program should be.  The user can specify the verbosity at run-time.  This is particularly helpful when you want debug by printing lots of diagnostic information and then return to normal (info level) logging when the issue is resolved.

Consider an example case were we are having trouble with the map_server node.  We wish to turn up the verbosity by specifying that the DEBUG messages should be printed to the screen.  There are a few ways to accomplish this, some of which are presented below.

Create a rosconsole Config File

You will need a configuration file to specify that we want to logging level of the map_server package to be DEBUG.  The example below is supplied in the mrc_examples ROS package and as config/custom_rosconsole.conf.

Code Block
#   config/custom_rosconsole.conf
#   You can define your own by e.g. copying this file and setting
#   ROSCONSOLE_CONFIG_FILE (in your environment) to point to the new file
#
log4j.logger.ros=INFO
log4j.logger.ros.map_server=DEBUG
log4j.logger.ros.roscpp.superdebug=WARN

This config file explicitly sets the logging level to DEBUG for the map_server package.

Method 1: Using the Custom Config in a Launch File

We can specify the use of this custom configuration file within a launch file.  We also direct the map_server node output to the screen as demonstrated in the launch/map_server_debug.launch example.

Code Block
<?xml version="1.0"?>
<launch>
	<!-- Optional input argument -->
	<arg name="map_file" default="$(find turtlebot3_navigation)/maps/map.yaml"/>

	<env name="ROSCONSOLE_CONFIG_FILE" value="$(find mrc_examples)/config/custom_rosconsole.conf"/>	

  <node pkg="map_server" name="map_server" type="map_server" args="$(arg map_file)" output="screen"/>

</launch>

You can run this example by cloning the  mrc_examples ROS package (catkin_make, source ~/catkin_ws/devel/setup.bash, etc.) and...

Code Block
roslaunch mrc_examples map_server_debug.launch 

which should generate output similar to...

Code Block
... logging to /home/bsb/.ros/log/e41f91aa-8266-11e9-a998-408d5c555554/roslaunch-aku-30928.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://aku:42735/

SUMMARY
========

PARAMETERS
 * /rosdistro: kinetic
 * /rosversion: 1.12.14

NODES
  /
    map_server (map_server/map_server)

ROS_MASTER_URI=http://localhost:11311

process[map_server-1]: started with pid [30945]
[DEBUG] [1559172059.429037519]: The map does not contain a mode tag or it is invalid... assuming Trinary
[ INFO] [1559172059.429102024]: Loading map from image "/home/bsb/mrc_ws/src/turtlebot3/turtlebot3_navigation/maps/./map.pgm"
[ INFO] [1559172059.429845193]: Read a 384 X 384 map @ 0.050 m/cell
^C[map_server-1] killing on exit
shutting down processing monitor...
... shutting down processing monitor complete
done

where we can see that the DEBUG message is being printed to the screen.

Method 2: Using Environment Variable 

An alternative is to set an environment variable to point to our config file...

Code Block
export ROSCONSOLE_CONFIG_FILE=~/mrc_ws/src/mrc_examples/config/custom_rosconsole.conf

and then run the map server node...

Code Block
rosrun map_server map_server /home/bsb/mrc_ws/src/turtlebot3/turtlebot3_navigation/maps/map.yaml 

which should have the same result.   For this method we have to be a bit more explicit by providing the full path to the configuration and map files.