Get spawner logger from node to respect remapped names (#3446)#3462
Get spawner logger from node to respect remapped names (#3446)#3462Rishitha2628 wants to merge 3 commits into
Conversation
…3446) Signed-off-by: Rishitha2628 <mr21ecb0a33@student.nitw.ac.in>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3462 +/- ##
=======================================
Coverage 89.52% 89.53%
=======================================
Files 164 164
Lines 21270 21271 +1
Branches 1656 1657 +1
=======================================
+ Hits 19042 19044 +2
- Misses 1526 1527 +1
+ Partials 702 700 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
saikishor
left a comment
There was a problem hiding this comment.
Thank you for the PR, I'm not sure if it is a good idea to proceed with this change. I've left a comment on why we shouldn't. Let's see what others say
| node = Node(spawner_node_name) | ||
| logger = node.get_logger() |
There was a problem hiding this comment.
There is a reason we didn't create the node earlier, when there are multiple nodes created at the startup of the robot, somehow it is affecting the determism of the spawners. It is something in the RMW layer. For the determinism reasons, I would leave it as it is right now
There was a problem hiding this comment.
Thanks, that makes sense — the determinism constraint isn't visible from the code or git history, which is probably why #3446 suggested this approach. Curious what the others think, since the /rosout logging gap is still real either way, though worth noting it only affects the lock-acquisition messages (mostly debug/warning level), since everything after node creation already logs correctly.
There was a problem hiding this comment.
@saikishor we could have both if we create the node only after the lock is acquired (before the # print?) this only affects a few logger calls, where we can use a named logger (won't be published without a node, but we don't care then).
There was a problem hiding this comment.
Sure, we can replace the logger once the node is created.
There was a problem hiding this comment.
Applied, the node is now created right after the lock is acquired, so the lock-acquisition messages keep the named logger and everything from there on uses the node's logger. Added a comment about why the node is created after the lock.
saikishor
left a comment
There was a problem hiding this comment.
My opinion is not to proceed with this change, until the determinism issue is fixed
Signed-off-by: Rishitha2628 <mr21ecb0a33@student.nitw.ac.in>
christophfroehlich
left a comment
There was a problem hiding this comment.
Thanks for the follow-up.
But: I now question myself why I wrote this issue: In L430 the logger is overwritten with the node's logger, added with #2382 (I missed that before)
Which means that node name remapping already works also with the logger in /rosout. I cannot reproduce what I saw back then..
However, with this PR also the "Spawner lock acquired" log is published in the correct way.
Description
The spawner's logger was created from a hardcoded name
(
"ros2_control_controller_spawner_" + first_controller_name) before theNode existed. Since /rosout attribution is based on the node's actual name,
any log message emitted before
node.get_logger()was assigned — includingall the file-lock acquisition messages (waiting, timeout retries, failures) —
never reached /rosout when the node name was remapped at launch.
This PR creates the Node before the lock-acquisition loop and obtains the
logger from it via
node.get_logger(), so the logger always reflects thenode's actual (possibly remapped) name.
A fallback
rclpy.logging.get_logger("spawner")is kept before thetry:block to preserve the logger-scope guarantee from #2382: the exception
handlers and
finally:block referencelogger, which must exist even ifNode creation itself raises.
Some history: the Node was originally created before this logic; #2202 moved
it inside the try block when introducing the file lock, and #2382 then
hoisted a hardcoded logger out of the try block to fix a scope issue. This
PR effectively restores the original ordering while keeping both the lock
behavior and the scope guarantee.
Verified the mechanism with a minimal rclpy script on ROS 2 Humble: a logger
obtained from
rclpy.logging.get_logger("<hardcoded>")does not appear in/rosout, while
node.get_logger()messages appear with the node's remappedname.
unspawner.pyalready usesnode.get_logger()throughout and is notaffected.
Fixes #3446
Is this user-facing behavior change?
Yes, in a minor way: spawner log messages now appear in /rosout under the
node's actual (possibly remapped) name instead of the previous hardcoded
logger name
ros2_control_controller_spawner_<first_controller_name>.Anyone filtering /rosout by the old logger name would need to filter by the
node name instead.
Did you use Generative AI?
Yes — I used Claude (Anthropic) as a guide while working on this PR: it
helped me navigate the contribution workflow, review the git history of
spawner.py, and draft this description. The fix itself follows the approach
suggested in the issue, and I made and tested the code changes myself.
Additional Information
Relying on CI for the C++ integration tests (test_spawner_unspawner.cpp
etc.) on the target distros — I'm on ROS 2 Humble locally, so I verified
the rclpy logger mechanism directly rather than building the full stack.
TODOs
To send us a pull request, please:
colcon testandpre-commit run(requires you to install pre-commit bypip3 install pre-commit)