Rosanswers logo


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")

TICKET: https://github.com/ros2/rcl/issues/476

DISCOURSE: https://discourse.ros.org/t/set-symbol-visibility-to-hidden-for-rmw-and-rcl-packages/7981/5?u=alsora

Originally posted by alsora on ROS Answers with karma: 1322 on 2019-07-29

Post score: 0


1 Answer 1


Rosanswers logo

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 https://github.com/ros2/rcl/pull/478

rcl_logging_rosout_init should be marked with RCL_PUBLIC too since otherwise the handler is useless. https://github.com/ros2/rcl/pull/479

Originally posted by alsora with karma: 1322 on 2019-08-01

This answer was ACCEPTED on the original site

Post score: 0


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.