Ask Your Question
0

What is the intention of using spdlog under the hood?

asked 2020-09-16 15:31:55 -0600

Mbuijs gravatar image

So now (since eloquent?) the nice spdlog library is used under the hood for logging. I was wondering if there is any plan on further integration?

More specifically, I would look forward to having an API similar to spdlog while using rclcpp.

edit retag flag offensive close merge delete

Comments

While thinking about this question, I realized that spdlog comes with fmtlib, which seems to do the heavy lifting w.r.t. the string formatting. Since spdlog comes installed with ROS2 automatically, I can now do the following in my code:

#include <spdlog/fmt/fmt.h>

RCLCPP_INFO(get_logger(),
            fmt::format("Hello {}! Float formatting: {:.2f}", "world", 42.123456));
Mbuijs gravatar image Mbuijs  ( 2020-09-16 15:33:35 -0600 )edit

Yes, exactly. Could you perhaps give an example of what sort of API you would want specifically in rclcpp?

gvdhoorn gravatar image gvdhoorn  ( 2020-09-16 15:46:27 -0600 )edit

Something shorter like this:

RCLCPP_INFO(get_logger(), "Hello {}! Float formatting: {:.2f}", "world", 42.123456));

The question mainly comes from the point where I wonder what the benefit of the switch to spdlog is for the user. Using fmt::format was also possible already before the switch by just installing fmtlib and using it directly.

Mbuijs gravatar image Mbuijs  ( 2020-09-21 05:36:00 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-09-21 18:05:00 -0600

tfoote gravatar image

The switch to use spdlog was focused on implications for the underlying implmentation not for changing the user API. You can read more at https://github.com/ros2/rcl_logging/p...

The user API specifically doesn't expose spdlog or any other logging implementation through it's abstraction so that the implementation can be changed without requiring users to change their code. As you noticed we already took advantage of this to switch to spdlog. And in the future we could consider changing the default. But right now it's possible for a system integrator to swap out the logging mechanism for specific deployments too.

We have kept it as simple as possible and do not want to require the use of one specific formatting technology. As the user may want to user a different formatting tool than fmtlib.

edit flag offensive delete link more

Comments

Why? fmt is vastly superior to the printf style formatters that appear to be used (which interestingly aren't really mentioned at all in any of the logging documentation). It's also part of C++20)...It's seems like a shame and a huge missed opportunity (not to mention a step backward....

strike_eagle_iii gravatar image strike_eagle_iii  ( 2021-08-14 23:21:34 -0600 )edit

The whole point is that the API doesn't select what formatting library you use. You can use fmt or you can use printf. When you say printf appears to be used, that's likely because a lot of the code was written before fmt was available. And the lowest cost porting forward didn't include refactoring it to use the newer logger which will require longer reviews and be prone to more errors. Feel free to go ahead and use the more modern fmt in your code, that's why the API is designed independently to give you the option, instead of forcing one or the other formatter.

tfoote gravatar image tfoote  ( 2021-08-16 16:25:23 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2020-09-16 15:31:55 -0600

Seen: 308 times

Last updated: Sep 21 '20