@@ -26,6 +26,7 @@ extern "C"
2626
2727#include "rcl/arguments.h"
2828#include "rcl/error_handling.h"
29+ #include "rcl/logging.h"
2930#include "rcl/logging_rosout.h"
3031#include "rcl/rcl.h"
3132#include "rcl/remap.h"
@@ -355,17 +356,19 @@ rcl_node_init(
355356 }
356357 // The initialization for the rosout publisher requires the node to be in initialized to a point
357358 // that it can create new topic publishers
358- ret = rcl_logging_rosout_init_publisher_for_node (node );
359- if (ret != RCL_RET_OK ) {
360- // error message already set
361- goto fail ;
359+ if (g_rcl_logging_rosout_enabled ) {
360+ ret = rcl_logging_rosout_init_publisher_for_node (node );
361+ if (ret != RCL_RET_OK ) {
362+ // error message already set
363+ goto fail ;
364+ }
362365 }
363366 RCUTILS_LOG_DEBUG_NAMED (ROS_PACKAGE_NAME , "Node initialized" );
364367 ret = RCL_RET_OK ;
365368 goto cleanup ;
366369fail :
367370 if (node -> impl ) {
368- if (node -> impl -> logger_name ) {
371+ if (g_rcl_logging_rosout_enabled && node -> impl -> logger_name ) {
369372 ret = rcl_logging_rosout_fini_publisher_for_node (node );
370373 RCUTILS_LOG_ERROR_EXPRESSION_NAMED ((ret != RCL_RET_OK && ret != RCL_RET_NOT_INIT ),
371374 ROS_PACKAGE_NAME , "Failed to fini publisher for node: %i" , ret );
@@ -431,10 +434,13 @@ rcl_node_fini(rcl_node_t * node)
431434 }
432435 rcl_allocator_t allocator = node -> impl -> options .allocator ;
433436 rcl_ret_t result = RCL_RET_OK ;
434- rcl_ret_t rcl_ret = rcl_logging_rosout_fini_publisher_for_node (node );
435- if (rcl_ret != RCL_RET_OK && rcl_ret != RCL_RET_NOT_INIT ) {
436- RCL_SET_ERROR_MSG ("Unable to fini publisher for node." );
437- result = RCL_RET_ERROR ;
437+ rcl_ret_t rcl_ret = RCL_RET_OK ;
438+ if (g_rcl_logging_rosout_enabled ) {
439+ rcl_ret = rcl_logging_rosout_fini_publisher_for_node (node );
440+ if (rcl_ret != RCL_RET_OK && rcl_ret != RCL_RET_NOT_INIT ) {
441+ RCL_SET_ERROR_MSG ("Unable to fini publisher for node." );
442+ result = RCL_RET_ERROR ;
443+ }
438444 }
439445 rmw_ret_t rmw_ret = rmw_destroy_node (node -> impl -> rmw_node_handle );
440446 if (rmw_ret != RMW_RET_OK ) {
0 commit comments