-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give nodes a logger #148
Give nodes a logger #148
Conversation
rclpy/rclpy/__init__.py
Outdated
@@ -16,6 +16,7 @@ | |||
|
|||
from rclpy.executors import SingleThreadedExecutor as _SingleThreadedExecutor | |||
from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy | |||
import rclpy.logging # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why import this in __init__.py
? Is it to initialize the root_logger before rclpy.init()
is called? What breaks if this import doesn't happen here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing breaks, it's just to save users from having to import it themselves in each script that wants to use logging. I can add a comment for it but I'm not sure which other lines in this section are doing it for the same reason
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand __init__.py
, but if I comment this line out rclpy.logging
appears to be imported regardless.
$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import rclpy
>>> rclpy.logging.logerr("Hello World!")
[ERROR] []: Hello World! (<module>() at /workspace/ros2_ws/<stdin>:1)
True
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, it was necessary on master to use the non-node logging methods, but since node.py is importing it now, it's not needed here: a48d6b6
This reverts commit 40bfac5. The change isn't necessary anymore since node.py includes rclpy.logging
Please review this PR in combination with ros2/demos#190 to check that the usage is as expected. In particular, I opted for a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks fine to me, though I didn't attend the logger design discussion.
I would rather use a logger
attribute than get_logger()
. Properties can be used to do something more complicated in the future..
@ros2/team, following @sloretz's suggestion above, what do we think about:
We can raise when users try to set the attributes. I checked the PRs that added the other getters (#70 and #86) and there wasn't a discussion about why accessors have been used |
I don't have a problem with using properties rather than getters, but I only hesitate to avoid a difference with C++ where we cannot easily do that I think. |
I'm for using properties, as it is more pythonic in general. But I don't really have a strong opinion either way. |
I suppose it could be a bit counter-intuitive if it looks like an attribute but then raises when users try to set it. It might be more user-friendly to just give them the getters without setters if we don't want users to try to modify the names/logger after creation. Does that influence your opinion from a user perspective @sloretz ? |
May be related to the discussion (havent followed it) Lines 84 to 86 in 5c1b6e1
|
@dhood On point 2 my preference isn't strong enough for me to say the existing code should be changed. I think it would be fine to leave it as |
OK it doesn't seem like we have a strong enough motivation to swap to attributes, while "intuitiveness", existing code and similarity with c++ slightly lean us towards using getters, so the conclusion I'm drawing is that we'll stick with |
CI including changes in ros2/demos#190, will merge once comes back green |
name and namespace are not stored in Python land (not slots or attributes of the node class) so we need getters for them as we get them from rcl. If we want to take the same approach here we would never store the logger in python and get it from rcl everytime a user want to access it (which is totally fine IMO). Not saying we should change it here, I'm just wondering where we expect this to be stored in the future and if the decision is made only for being consistent with rclcpp and that it'll be inconsistent within rclpy only for the time being or if we chose to treat some attributes differently than others in rclpy for the long-term. |
They wouldn't need to be stored in Python. If we swap them to properties as with Line 82 in 5c1b6e1
Python has a notion of logger objects where rcl doesn't, so in this case it is appropriate for us to store the logger object associated with the node (this is what I envision for both short-term and long-term)
That's correct, but attributes with underscores are not considered public |
Edit (commenting so notification gets sent): "Python has a notion of logger objects where rcl doesn't" -> "rclpy has a notion of logger objects" (as of #102) |
Minimum required to switch demos to using node loggers: logger names are not using namespaces at the moment nor calling to rcl to get their logger name.