Skip to content

Commit

Permalink
added some comments explaining how this works
Browse files Browse the repository at this point in the history
  • Loading branch information
jncfa committed Jul 25, 2024
1 parent e8c62d8 commit 032c217
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
> What if we could just use spdlog instead?
This is a package that allows you to override the logging system in rcl/rclcpp to use spdlog!
I've done some concurrency tests with tsan&valgrind to ensure that this package is stable for now, but do beware that this isn't intended to be customizable by the rcl/rclcpp API

You can also run this quick test if you build
```bash
TEST_CONCURRENCY=1 ros2 run --prefix "valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-out.txt" ros2_spdlog_logger test_node
```
The tl;dr for how this works is, we replace [rclcpp's logging system initialization](https://github.com/ros2/rclcpp/blob/a4d7210b9cef081707ecec8aea7a7988ffd87b7f/rclcpp/src/rclcpp/context.cpp#L215-L234) with [our own](https://github.com/jncfa/ros2_spdlog_logger/blob/e8c62d89d88b3d5e1a182f860b129c70c5bb7633/src/ros2_spdlog_logger.cpp#L331-L339)!

We use our own [logging output handler](https://github.com/jncfa/ros2_spdlog_logger/blob/e8c62d89d88b3d5e1a182f860b129c70c5bb7633/src/ros2_spdlog_logger.cpp#L73-L136), that will capture all logging calls that rely on rclcpp macros, which before was rerouted to [rclcpp's logging output handler](https://github.com/ros2/rclcpp/blob/a4d7210b9cef081707ecec8aea7a7988ffd87b7f/rclcpp/src/rclcpp/context.cpp#L125-L143), and instead we run a very similar code to what the underlying [rcutils logging call](https://github.com/ros2/rcutils/blob/cf3e9986a557e4c893eb718b90c77ce189494a11/src/logging.c#L1373-L1465) would do.

I've done quite a bit of testing with this package and found no issues, but please understand that this is relying on some rcl/rclcpp internal API that may change in the future.
That being said, this should work for any ROS2 distribution from at least Foxy up to Jazzy.

0 comments on commit 032c217

Please sign in to comment.