Skip to content

Document changes to rclcpp's logging macros#949

Merged
audrow merged 6 commits intomasterfrom
audrow/galactic-rclcpp-logging-change
Dec 18, 2020
Merged

Document changes to rclcpp's logging macros#949
audrow merged 6 commits intomasterfrom
audrow/galactic-rclcpp-logging-change

Conversation

@audrow
Copy link
Copy Markdown
Member

@audrow audrow commented Dec 15, 2020

This PR documents the changes from ros2/rclcpp#1442.

Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
@mjcarroll mjcarroll temporarily deployed to ros2-documentation-pr-949 December 15, 2020 20:58 Inactive
@audrow audrow self-assigned this Dec 15, 2020
Copy link
Copy Markdown
Contributor

@clalancette clalancette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some suggestions to give users more context on what they may need to change.

@clalancette
Copy link
Copy Markdown
Contributor

(also, this PR should not be merged until we land ros2/rclcpp#1442)

audrow and others added 3 commits December 17, 2020 09:05
Signed-off-by: Audrow Nash <audrow.nash@gmail.com>

Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
@mjcarroll mjcarroll temporarily deployed to ros2-documentation-pr-949 December 17, 2020 17:34 Inactive
Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
@mjcarroll mjcarroll temporarily deployed to ros2-documentation-pr-949 December 17, 2020 18:43 Inactive
@audrow
Copy link
Copy Markdown
Member Author

audrow commented Dec 17, 2020

I've updated the std::string with format args case to mention that doing so will raise a -Wformat-security warning (example here), talked about how to get around this, and added an example of using std::string with no format arguments.

@audrow audrow requested a review from clalancette December 17, 2020 18:47
Comment on lines +148 to +162
If you are using a ``std::string`` as a format string with format arguments, converting that string to a ``char *`` and using it as the format string will yield a format security warning. To avoid the security warning, we recommend you build the string manually and pass it as in with no format arguments like the previous example.

If you don't care about the ``-Wformat-security`` warning and you previously had code like:

.. code-block::

std::string my_std_string = "Foo %d";
RCLCPP_DEBUG(get_logger(), my_std_string, 5);

you could replace it with:

.. code-block::

std::string my_std_string = "Foo %d";
RCLCPP_DEBUG(get_logger(), my_std_string.c_str(), 5); // raises -Wformat-security warning
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, I think this is somewhat redundant with the previous example. Also, I think we should explain why it ends up with the -Wformat-security warning. So I'd think about replacing this entire block with:

Note: if you are using a ``std::string`` as a format string with format arguments, converting that string to a ``char *`` and using it as the format string will yield a format security warning. That's because the compiler has no way at compile to introspect into the ``std::string`` to verify the arguments.  To avoid the security warning, we recommend you build the string manually and pass it in with no format arguments like the previous example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I think this makes it much clearer.

Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
@audrow audrow merged commit 2d1d6d8 into master Dec 18, 2020
@delete-merged-branch delete-merged-branch bot deleted the audrow/galactic-rclcpp-logging-change branch December 18, 2020 17:47
clalancette added a commit that referenced this pull request Mar 11, 2021
* Add changes to rclcpp's logging macros

Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
mergify bot pushed a commit that referenced this pull request Mar 11, 2021
* Add changes to rclcpp's logging macros

Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
(cherry picked from commit 15eb141)
mergify bot pushed a commit that referenced this pull request Mar 11, 2021
* Add changes to rclcpp's logging macros

Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
(cherry picked from commit 15eb141)
clalancette pushed a commit that referenced this pull request Mar 11, 2021
* Add changes to rclcpp's logging macros

Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
(cherry picked from commit 15eb141)

Co-authored-by: Audrow Nash <audrow.nash@gmail.com>
clalancette pushed a commit that referenced this pull request Mar 11, 2021
* Add changes to rclcpp's logging macros

Signed-off-by: Audrow Nash <audrow.nash@gmail.com>
Co-authored-by: Chris Lalancette <clalancette@openrobotics.org>
(cherry picked from commit 15eb141)

Co-authored-by: Audrow Nash <audrow.nash@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants