ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

get_logger

asked 2020-05-20 11:04:20 -0500

forbiddenfruit gravatar image

Hey folks. Very beginner question as I was experimenting with both C++ and Python.

With C++ i found that you can print to screen using:

RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "BLAH BLAH BLAH");

Now I wanted to do the same thing with Python, however, so far i have only been able to call the get_logger function inside of a node class. How can i do it outside of it similar to its C++ counterpart?

I was thinking it should be similar:

RCLPY_INFO(rclpy.logging.get_logger().info("rclpy"), "BLAH BLAH BLAH")

but ofcourse it is not.

Any help would be great thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-05-20 12:38:25 -0500

This example: https://github.com/ros2/examples/blob... should get you on your way.

Looks like you need to use get_logger() in python to store the logging object and then just call it to log info, error, etc

edit flag offensive delete link more

Comments

I want to specifically use it outside of a node. I dont want to call self.get_logger etc. I want to imitate the call for the C++ in python

forbiddenfruit gravatar image forbiddenfruit  ( 2020-05-20 20:00:05 -0500 )edit
1

You also need a logger object in C++ so that's not any different. RCLPY_INFO macros don't exist. All the RCLCPP_INFO does is take the logger and use it to print the message, that's what this is doing in python. If you use that as an example, your code is then logger = rclpy.logging.get_logger("random_name"), and then use logger.info("msg") to log.

stevemacenski gravatar image stevemacenski  ( 2020-05-20 20:05:34 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2020-05-20 11:04:20 -0500

Seen: 3,701 times

Last updated: May 20 '20