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

Add the possibility to use spdlog with YARP #408

Merged
merged 3 commits into from
Sep 3, 2021
Merged

Conversation

GiulioRomualdi
Copy link
Member

@GiulioRomualdi GiulioRomualdi commented Sep 2, 2021

This PR closes #407. In detail, I implemented a custom sink to handle the logging through yarp.

The switching between the normal logging to the yarp one is pretty simple and has been implemented using the factory pattern.

#include <BipedalLocomotion/TextLogging/Logger.h>
#include <BipedalLocomotion/TextLogging/YarpLogger.h>
#include <BipedalLocomotion/TextLogging/LoggerBuilder.h>
// Change the logger
BipedalLocomotion::TextLogging::LoggerBuilder::setFactory(std::make_shared<BipedalLocomotion::TextLogging::YarpLoggerFactory>()));

BipedalLocomotion::log()->info("My info");

will print

[INFO] [2021-09-02 23:20:43.501] [thread: 108475] [blf] My info

using yInfo()

Thanks to this feature all the applications that uses BipedalLocomotion::log can log all the info/errors in a yarp logger

@diegoferigo
Copy link
Member

Disclaimer: I didn't review the files yet.

Does this implementation change the logger in a process-wise manner? And I mean, if there are multiple systems (advanceables) running, but just one in its compile unit switches the logger to YARP, do all the logging -also of the other systems- be sunk to the new logger?

@GiulioRomualdi
Copy link
Member Author

GiulioRomualdi commented Sep 3, 2021

Does this implementation change the logger in a process-wise manner?

Since the logger is treated as a singleton the builder should be called before calling the first time log() (i.e. at the beginning of your main).

Then all the treads spawned by that application will use yarp to log

@diegoferigo
Copy link
Member

Ok, I guess that this operation will be done in the main() and then the entire application will dump to the right sink 👍

@traversaro
Copy link
Collaborator

Ok, I guess that this operation will be done in the main() and then the entire application will dump to the right sink 👍

Yes, I think that's the idea in general with spdlog loggers, at least the one provided by singletons .

@diegoferigo
Copy link
Member

Yep, this morning for some reason I was assuming this to be done in the Advanceable's code. But that makes no sense, hence I asked. From the main is definitely the intended pattern.

@GiulioRomualdi GiulioRomualdi merged commit 252e930 into master Sep 3, 2021
@GiulioRomualdi GiulioRomualdi deleted the spdlog/yarp branch September 3, 2021 11:53
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.

Implement the possibility to use spdlog for logging info in yarplogger
3 participants