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

Experimenting with spdlog #615

Merged
merged 38 commits into from
Aug 28, 2024
Merged

Experimenting with spdlog #615

merged 38 commits into from
Aug 28, 2024

Conversation

mjcarroll
Copy link
Contributor

No description provided.

Signed-off-by: Michael Carroll <[email protected]>
@mjcarroll mjcarroll self-assigned this Jul 2, 2024
mjcarroll and others added 5 commits July 3, 2024 15:08
Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
@j-rivero
Copy link
Contributor

Unsure if the comment is out of the scope of this work, please ignore it if it is.

The current implementation seems to support different "sinks" (destinations for the logging) in the sense that I can see the fileSink and consoleSink in the implementation of the ConsoleNew::Implementation. Even if the class naming and file naming is a bit confuse since we use "Console" all over the place.

I think that supported this variety of "sinks" is really a great approach so we can extend the logging capabilities in the future. Concretely I'm looking into experimenting with OpenTelemetry for the whole Gazebo and one of the options that this spdlog support can provide is the use of an "OpenTelemetry sink". The creation of it seems trivial if we can support multiple sinks somehow:

#include <opentelemetry/instrumentation/spdlog/sink.h>

auto otel_sink = std::make_shared<spdlog::sinks::opentelemetry_sink_mt>();
otel_sink->set_level(spdlog::level::info);
auto logger = spdlog::logger("OTelLogger", otel_sink);

@mjcarroll
Copy link
Contributor Author

The current implementation seems to support different "sinks" (destinations for the logging) in the sense that I can see the fileSink and consoleSink in the implementation of the ConsoleNew::Implementation. Even if the class naming and file naming is a bit confuse since we use "Console" all over the place.

That is correct. I used ConsoleNew to keep the name and behavior consistent with the current Console behavior. The current Console also sinks to file and stdout/stderr console streams.

In this implementation, I wanted to make sure that we can surface the underlying spdlog mechanisms so you could (for instance) add an OpenTelemetry sink to Console.

Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
@azeey
Copy link
Contributor

azeey commented Jul 26, 2024

Would it make sense to move this into gz-utils? We have an implementation of Console in sdformat which could be replaced with this. I was also working on gazebosim/gz-math#613 which needs to enforce an invariant. Since we don't use exceptions, this will probably resort to printing an error message, which we do in many places in gz-math. It would be nice if we had proper logging there as well.

Signed-off-by: Carlos Agüero <[email protected]>
@azeey azeey added the beta Targeting beta release of upcoming collection label Jul 29, 2024
@azeey
Copy link
Contributor

azeey commented Jul 30, 2024

@mjcarroll and I discussed putting a lightweight wrapper around spdlog in gz-utils which would allow us to use it in libraries such as gz-math or sdformat. We would still have the higher level API, aka common::Console here which will have more functionality. This would provide a way for downstream applications like gz-sim capture and redirect console output from gz-math or sdformat and display them however they want.

Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
@azeey azeey added the Breaking change Breaks API, ABI or behavior. Must target unstable version. label Aug 20, 2024
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Copy link

codecov bot commented Aug 26, 2024

Codecov Report

Attention: Patch coverage is 84.12698% with 10 lines in your changes missing coverage. Please review.

Project coverage is 84.92%. Comparing base (316ea33) to head (0b479c3).
Report is 8 commits behind head on main.

Files Patch % Lines
src/Console.cc 84.12% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #615      +/-   ##
==========================================
+ Coverage   80.54%   84.92%   +4.38%     
==========================================
  Files          80       78       -2     
  Lines       13588    10094    -3494     
==========================================
- Hits        10944     8572    -2372     
+ Misses       2644     1522    -1122     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Carlos Agüero <[email protected]>
package.xml Outdated Show resolved Hide resolved
@iche033
Copy link
Contributor

iche033 commented Aug 26, 2024

update migration guide?

Signed-off-by: Carlos Agüero <[email protected]>
@iche033
Copy link
Contributor

iche033 commented Aug 26, 2024

I tested this with gz-sim's main branch and I noticed a couple of issues.

  1. This first one is minor - there are now empty lines between console log entries
[2024-08-26 21:48:33.501] [gz] [info] [SceneBroadcaster.cc:634] Serving scene information on [/world/shapes/scene/info]

[2024-08-26 21:48:33.502] [gz] [info] [SceneBroadcaster.cc:643] Serving graph information on [/world/shapes/scene/graph]

[2024-08-26 21:48:33.502] [gz] [info] [SceneBroadcaster.cc:654] Serving full state on [/world/shapes/state]
  1. I get a crash if I try to close the GUI window:
terminate called after throwing an instance of 'std::system_error'
...
...
#13   Object "/lib/x86_64-linux-gnu/libspdlog.so.1.12", at 0x7fa4dfdb3400, in spdlog::details::registry::~registry()
#12   Object "/lib/x86_64-linux-gnu/libspdlog.so.1.12", at 0x7fa4dfde771b, in spdlog::details::periodic_worker::~periodic_worker()

Signed-off-by: Carlos Agüero <[email protected]>
@caguero
Copy link
Contributor

caguero commented Aug 26, 2024

update migration guide?

Updated in 27633b7

testing/src/AutoLogFixture_TEST.cc Outdated Show resolved Hide resolved
src/Console_TEST.cc Show resolved Hide resolved
src/Console_TEST.cc Show resolved Hide resolved
test/integration/console.cc Outdated Show resolved Hide resolved
EXPECT_TRUE(logContent.find("**test** [Wrn]") != std::string::npos);
EXPECT_TRUE(logContent.find("**test** [Msg]") != std::string::npos);
EXPECT_TRUE(logContent.find("**test** [Dbg]") != std::string::npos);
EXPECT_TRUE(logContent.find("**test** error") != std::string::npos);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a behavior change on the formatting of the logs? Should this be included in the migration guide?

src/Console.cc Outdated Show resolved Hide resolved
@iche033
Copy link
Contributor

iche033 commented Aug 26, 2024

Added gz-utils3-log / spdlog dependency to:

windows has spdlog dependency already (gazebo-tooling/release-tools#1163)

@caguero caguero mentioned this pull request Aug 27, 2024
8 tasks
@caguero
Copy link
Contributor

caguero commented Aug 27, 2024

I tested this with gz-sim's main branch and I noticed a couple of issues.

  1. This first one is minor - there are now empty lines between console log entries
[2024-08-26 21:48:33.501] [gz] [info] [SceneBroadcaster.cc:634] Serving scene information on [/world/shapes/scene/info]

[2024-08-26 21:48:33.502] [gz] [info] [SceneBroadcaster.cc:643] Serving graph information on [/world/shapes/scene/graph]

[2024-08-26 21:48:33.502] [gz] [info] [SceneBroadcaster.cc:654] Serving full state on [/world/shapes/state]
  1. I get a crash if I try to close the GUI window:
terminate called after throwing an instance of 'std::system_error'
...
...
#13   Object "/lib/x86_64-linux-gnu/libspdlog.so.1.12", at 0x7fa4dfdb3400, in spdlog::details::registry::~registry()
#12   Object "/lib/x86_64-linux-gnu/libspdlog.so.1.12", at 0x7fa4dfde771b, in spdlog::details::periodic_worker::~periodic_worker()

Could you try with this PR? gazebosim/gz-utils#139

I think we should use a period flush for efficiency but we might be doing something wrong and I suspect it's related with the use of static. This could be a workaround until we learn more about the issue.

@iche033
Copy link
Contributor

iche033 commented Aug 27, 2024

Could you try with this PR? gazebosim/gz-utils#139

tested and confirmed it fixes the issues.

caguero and others added 5 commits August 28, 2024 16:52
Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
* Remove flushes and fix tests

Signed-off-by: Addisu Z. Taddese <[email protected]>

* Remove doxygen parameter

Signed-off-by: Carlos Agüero <[email protected]>

---------

Signed-off-by: Addisu Z. Taddese <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Co-authored-by: Carlos Agüero <[email protected]>
@caguero caguero merged commit 6cb5a53 into main Aug 28, 2024
10 checks passed
@caguero caguero deleted the mjcarroll/spdlog branch August 28, 2024 23:50
@caguero
Copy link
Contributor

caguero commented Aug 29, 2024

@Mergifyio backport gz-common6

Copy link

mergify bot commented Aug 29, 2024

backport gz-common6

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Aug 29, 2024
* spdlog logging integration.

Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
(cherry picked from commit 6cb5a53)
iche033 pushed a commit that referenced this pull request Aug 29, 2024
* spdlog logging integration.

Signed-off-by: Michael Carroll <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Addisu Z. Taddese <[email protected]>
(cherry picked from commit 6cb5a53)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beta Targeting beta release of upcoming collection Breaking change Breaks API, ABI or behavior. Must target unstable version. 🏛️ ionic
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants