Skip to content
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

Replace fprintf with ROS 2 logging #16

Open
sloretz opened this issue Aug 19, 2020 · 4 comments
Open

Replace fprintf with ROS 2 logging #16

sloretz opened this issue Aug 19, 2020 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@sloretz
Copy link

sloretz commented Aug 19, 2020

The Model class communicates error messages by calling fprintf()

fprintf(stderr, "Could not open file [%s] for parsing.\n", filename.c_str());

This should instead use ROS 2's logging functionality. This might mean passing in a logger instance to the class.

See also:

#13 (review)
#13 (comment)

@guru-florida
Copy link

Should the parse do any writing to log files? As a suggestion, perhaps it could throw a parsing exception? The caller can then decide if the error should be logged or silent.

FYI I am resolving a similar issue over in ros2_controls URDF Transmissions parser (PR 182) and I figured I'd come over here to see how it was done and get a feel for precedence. Perhaps find an existing parsing exception class. @Karsten1987 suggested I remove the rclcpp dependency since I am only using it for logging in favor of rclutils logging directly. For now, I am going to switch the Transmission parsing class to throw runtime_error exception and there is also a simple convenience function that parses urdf Transmissions using that class that will catch the exception and send to rclutils logging (which rclcpp logging is based on). Eventually I'd like to integrate Transmissions parsing as part of this urdf module. Thoughts?

If you would like I can replace the fprintf calls with rclutils calls since I am doing the same thing over there. Unless you use other parts of rclcpp it reduces the dependency footprint.

@clalancette
Copy link

If you would like I can replace the fprintf calls with rclutils calls since I am doing the same thing over there. Unless you use other parts of rclcpp it reduces the dependency footprint.

As it stands, this package doesn't depend on either rclcpp or rcutils. I'd be in favor of using the RCUTILS macros, as adding a dependency on rclcpp just for logging seems too heavyweight. But I'd also like to hear @sloretz 's opinion on it.

@sloretz
Copy link
Author

sloretz commented Oct 22, 2020

As it stands, this package doesn't depend on either rclcpp or rcutils. I'd be in favor of using the RCUTILS macros, as adding a dependency on rclcpp just for logging seems too heavyweight.

Agreed - I would use the rcutils API for this package. As far as I can tell that only requires including the macros and using them.

#include <rcutils/logging_macros.h>
// ...
        RCUTILS_LOG_WARN_NAMED(
          "my_package", "Blah Bla Blah [%s] failed", some_str.c_str());
// ...

FYI I am resolving a similar issue over in ros2_controls URDF Transmissions parser (PR 182) and I figured I'd come over here to see how it was done and get a feel for precedence. Perhaps find an existing parsing exception class.

@guru-florida You might find inspiration in SDFormat's Errors class. The APIs sdf::read[String|File|Xml]() Return a bool, but also offer Errors which has info in case it does fail.

@ahcorde
Copy link

ahcorde commented Aug 21, 2024

Related PR #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants