rospy.loginfo('GoToPositionRequest Received - j1:%s, j2:%s', req.joint_1, req.joint_2)
By default all logging messages for a node are written to the node's log file which can be found in ~/.ros/log
or ROS_ROOT/log
.
If roscore
is running, you can use roscd
to find log file directory by opening a new terminal window and typing:
roscd log
In this directory, you should see directories from runs of your ROS code, along with a latest
directory with log files from the most recent run.
7.1 Logging levels and outputs
rospy.logdebug(...)
rospy.loginfo(...)
rospy.logwarn(...)
rospy.logerr(...)
rospy.logfatal(...)
All levels of logging messages are recorded in ROS log files, but some message levels may also be sent to Python stdout
, Python stderr
, or the ROS topic /rosout
.
The loginfo
messages are written to Python's stdout
, while logwarn
, logerr
, and logfatal
are written to Python's stderr
by default. Additionally, loginfo
, logwarn
, logerr
, and logfatal
are written to /rosout
.
More in http://wiki.ros.org/rospy/Overview/Logging
7.2 Filtering and saving log messages from /rosout
Note that for messages written to /rosout
, you can see the messages in real time as your program is running by echoing:
rostopic echo /rosout
一般可以用grep来过滤有用信息
rostopic echo /rosout | grep insert_search_expression_here
rostopic echo /rosout | grep insert_search_expression_here > path_to_output/output.txt
7.3 Modifying message level sent to /rosout
To do this you must set the log_level
attribute within the rospy.init_node
code.
For example, if you'd like to allow logdebug messages to be written to /rosout
, that can be done as follows:
rospy.init_node('my_node', log_level=rospy.DEBUG)
7.4 Modifying display of messages sent to stdout
and stderr
It is also possible to change how messages to stdout
and stderr
are displayed or logged. Within a package's .launch
file, the output
attribute for a node tag can be set to "screen"
or "log"
. The following table summarizes how the different output options change the display of the node's stdout
and stderr
messages:
For example, setting output="screen"
for the look_away
node in robot_spawn.launch
will display both stdout
and stderr
messages in the screen:
<!-- The look away node -->
<node name="look_away" type="look_away" pkg="simple_arm" output="screen"/>
If the output
attribute is left empty, the default is "log"
.