Skip to content

Commit 1d0cc63

Browse files
authored
Create sublogger for action server and action client (#982)
Signed-off-by: Tony Najjar <tony.najjar@logivations.com>
1 parent 7685ee2 commit 1d0cc63

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

rclpy/rclpy/action/client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ def __init__(
180180

181181
callback_group.add_entity(self)
182182
self._node.add_waitable(self)
183+
self._logger = self._node.get_logger().get_child('action_client')
183184

184185
def _generate_random_uuid(self):
185186
return UUID(uuid=list(uuid.uuid4().bytes))
@@ -300,7 +301,7 @@ async def execute(self, taken_data):
300301

301302
self._pending_goal_requests[sequence_number].set_result(goal_handle)
302303
else:
303-
self._node.get_logger().warning(
304+
self._logger.warning(
304305
'Ignoring unexpected goal response. There may be more than '
305306
f"one action server for the action '{self._action_name}'"
306307
)
@@ -310,7 +311,7 @@ async def execute(self, taken_data):
310311
if sequence_number in self._pending_cancel_requests:
311312
self._pending_cancel_requests[sequence_number].set_result(cancel_response)
312313
else:
313-
self._node.get_logger().warning(
314+
self._logger.warning(
314315
'Ignoring unexpected cancel response. There may be more than '
315316
f"one action server for the action '{self._action_name}'"
316317
)
@@ -320,7 +321,7 @@ async def execute(self, taken_data):
320321
if sequence_number in self._pending_result_requests:
321322
self._pending_result_requests[sequence_number].set_result(result_response)
322323
else:
323-
self._node.get_logger().warning(
324+
self._logger.warning(
324325
'Ignoring unexpected result response. There may be more than '
325326
f"one action server for the action '{self._action_name}'"
326327
)

rclpy/rclpy/action/server.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -262,14 +262,15 @@ def __init__(
262262

263263
callback_group.add_entity(self)
264264
self._node.add_waitable(self)
265+
self._logger = self._node.get_logger().get_child('action_server')
265266

266267
async def _execute_goal_request(self, request_header_and_message):
267268
request_header, goal_request = request_header_and_message
268269
goal_uuid = goal_request.goal_id
269270
goal_info = GoalInfo()
270271
goal_info.goal_id = goal_uuid
271272

272-
self._node.get_logger().debug('New goal request with ID: {0}'.format(goal_uuid.uuid))
273+
self._logger.debug('New goal request with ID: {0}'.format(goal_uuid.uuid))
273274

274275
# Check if goal ID is already being tracked by this action server
275276
with self._lock:
@@ -280,7 +281,7 @@ async def _execute_goal_request(self, request_header_and_message):
280281
# Call user goal callback
281282
response = await await_or_execute(self._goal_callback, goal_request.goal)
282283
if not isinstance(response, GoalResponse):
283-
self._node.get_logger().warning(
284+
self._logger.warning(
284285
'Goal request callback did not return a GoalResponse type. Rejecting goal.')
285286
else:
286287
accepted = GoalResponse.ACCEPT == response
@@ -294,7 +295,7 @@ async def _execute_goal_request(self, request_header_and_message):
294295
with self._lock:
295296
goal_handle = ServerGoalHandle(self, goal_info, goal_request.goal)
296297
except RuntimeError as e:
297-
self._node.get_logger().error(
298+
self._logger.error(
298299
'Failed to accept new goal with ID {0}: {1}'.format(goal_uuid.uuid, e))
299300
accepted = False
300301
else:
@@ -307,34 +308,34 @@ async def _execute_goal_request(self, request_header_and_message):
307308
self._handle.send_goal_response(request_header, response_msg)
308309

309310
if not accepted:
310-
self._node.get_logger().debug('New goal rejected: {0}'.format(goal_uuid.uuid))
311+
self._logger.debug('New goal rejected: {0}'.format(goal_uuid.uuid))
311312
return
312313

313-
self._node.get_logger().debug('New goal accepted: {0}'.format(goal_uuid.uuid))
314+
self._logger.debug('New goal accepted: {0}'.format(goal_uuid.uuid))
314315

315316
# Provide the user a reference to the goal handle
316317
await await_or_execute(self._handle_accepted_callback, goal_handle)
317318

318319
async def _execute_goal(self, execute_callback, goal_handle):
319320
goal_uuid = goal_handle.goal_id.uuid
320-
self._node.get_logger().debug('Executing goal with ID {0}'.format(goal_uuid))
321+
self._logger.debug('Executing goal with ID {0}'.format(goal_uuid))
321322

322323
try:
323324
# Execute user callback
324325
execute_result = await await_or_execute(execute_callback, goal_handle)
325326
except Exception as ex:
326327
# Create an empty result so that we can still send a response to the client
327328
execute_result = self._action_type.Result()
328-
self._node.get_logger().error('Error raised in execute callback: {0}'.format(ex))
329+
self._logger.error('Error raised in execute callback: {0}'.format(ex))
329330
traceback.print_exc()
330331

331332
# If user did not trigger a terminal state, assume aborted
332333
if goal_handle.is_active:
333-
self._node.get_logger().warning(
334+
self._logger.warning(
334335
'Goal state not set, assuming aborted. Goal ID: {0}'.format(goal_uuid))
335336
goal_handle.abort()
336337

337-
self._node.get_logger().debug(
338+
self._logger.debug(
338339
'Goal with ID {0} finished with state {1}'.format(goal_uuid, goal_handle.status))
339340

340341
# Set result
@@ -346,7 +347,7 @@ async def _execute_goal(self, execute_callback, goal_handle):
346347
async def _execute_cancel_request(self, request_header_and_message):
347348
request_header, cancel_request = request_header_and_message
348349

349-
self._node.get_logger().debug('Cancel request received: {0}'.format(cancel_request))
350+
self._logger.debug('Cancel request received: {0}'.format(cancel_request))
350351

351352
with self._lock:
352353
# Get list of goals that are requested to be canceled
@@ -370,7 +371,7 @@ async def _execute_cancel_request(self, request_header_and_message):
370371
# that will generate an exception from invalid transition.
371372
goal_handle._update_state(GoalEvent.CANCEL_GOAL)
372373
except RCLError as ex:
373-
self._node.get_logger().debug(
374+
self._logger.debug(
374375
'Failed to cancel goal in cancel callback: {0}'.format(ex))
375376
# Remove from response since goal has been succeeded
376377
cancel_response.goals_canceling.remove(goal_info)
@@ -384,12 +385,12 @@ async def _execute_get_result_request(self, request_header_and_message):
384385
request_header, result_request = request_header_and_message
385386
goal_uuid = result_request.goal_id.uuid
386387

387-
self._node.get_logger().debug(
388+
self._logger.debug(
388389
'Result request received for goal with ID: {0}'.format(goal_uuid))
389390

390391
# If no goal with the requested ID exists, then return UNKNOWN status
391392
if bytes(goal_uuid) not in self._goal_handles:
392-
self._node.get_logger().debug(
393+
self._logger.debug(
393394
'Sending result response for unknown goal ID: {0}'.format(goal_uuid))
394395
result_response = self._action_type.Impl.GetResultService.Response()
395396
result_response.status = GoalStatus.STATUS_UNKNOWN

0 commit comments

Comments
 (0)