ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

ROS2 how to programmatically set rosout logging handler

asked 2019-07-29 08:47:50 -0500

alsora gravatar image

updated 2019-07-29 13:46:40 -0500


In ROS2 there are different types of logging handlers.

Command line arguments can be used to setup the loggers: these are passed to rclcpp::init() and then to rcl::init(). The command line arguments can do the following: enable stdout logging, enable rosout logging, enable an external logging library (log4cxx or spdlog). They do this by creating a logging_multiple_output_handler and setting it through rcutils_logging_set_output_handler.

I found myself in a situation where I want to use my own version of logging_multiple_output_handler. These handler should always use 2 loggers: rosout and an additional one that I'm defining.

For this reason, I created a function to be called right after rclcpp::init in order to re-initialize the logging handlers to what I need.

void set_ros2_logger_handler()

  auto allocator = rcl_get_default_allocator();

  auto logging_multiple_output_handler =
    const rcutils_log_location_t * location,
    int severity, const char * name, rcutils_time_point_value_t timestamp,
    const char * format, va_list * args) -> void
        rcl_logging_rosout_output_handler(location, severity, name, timestamp, format, args);
        my_custom_handler(location, severity, name, timestamp, format, args);


However, this does not really work and I'm wondering what should be the best approach. The problems are the following:

  • rcl_logging_rosout_init is a hidden function (marked with RCL_LOCAL) so how can I know if rosout has been enabled without using it?
  • rcl_logging_rosout_output_handler is not declared as hidden, but still I can't link to it for some reason.

EDIT: apparently rcl_logging_rosout_output_handler should be accessible and the error is linked to the following line in rcl/CMakeLists.txt

rcl_set_symbol_visibility_hidden(${PROJECT_NAME} LANGUAGE "C")



edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-08-01 09:17:13 -0500

alsora gravatar image

The code I posted is supposed to work.

rcl_logging_rosout_output_handler is marked as RCL_PUBLIC, but it was not accessible due to a bug addressed by this PR

rcl_logging_rosout_init should be marked with RCL_PUBLICtoo since otherwise the handler is useless.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-07-29 08:47:50 -0500

Seen: 543 times

Last updated: Aug 01 '19