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

Global logger for logging without a node

asked 2020-06-29 00:04:25 -0600

Rufus gravatar image

So far, all the examples I've seen for logging involves using the get_logger() method of rclcpp::Node, e.g.

RCLCPP_INFO(get_logger(), "my_message");

Is there a global logger that is can be used for logging without having access to a node?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2020-06-29 00:09:47 -0600

Rufus gravatar image

updated 2022-04-23 10:18:54 -0600

Turns out loggers can be created on the fly with rclcpp::get_logger for your logging purposes. e.g.

RCLCPP_INFO(rclcpp::get_logger("my_logger"), "my_message");

Also, remember to set the following if you're not seeing any log outputs (took me way too long to figure it out...)

export RCUTILS_CONSOLE_STDOUT_LINE_BUFFERED=1

In newer ROS versions, it should be

export RCUTILS_LOGGING_USE_STDOUT=1 && export RCUTILS_LOGGING_BUFFERED_STREAM=1
edit flag offensive delete link more

Comments

Does someone have an answer for rclpy?

tnajjar gravatar image tnajjar  ( 2022-01-18 10:40:02 -0600 )edit
2

answered 2023-04-17 14:22:00 -0600

zkytony gravatar image

In response to @tnajjar, to do this in Python, use RcutilsLogger under rclpy.impl

from rclpy.impl import rcutils_logger
logger = rcutils_logger.RcutilsLogger(name="my_logger")
logger.info("Hello World")

You will see something like

[INFO] [1681758901.959964134] [my_logger]: Hello World

Underneath the hood, some function from rcutils is called that does the job of logging.

edit flag offensive delete link more

Comments

Thank you, I'll definitely try it out

tnajjar gravatar image tnajjar  ( 2023-04-17 14:24:14 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2020-06-29 00:04:25 -0600

Seen: 2,457 times

Last updated: Apr 17 '23