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

Fix logging source location #150

Open
wants to merge 4 commits into
base: gz-utils3
Choose a base branch
from

Conversation

caguero
Copy link
Contributor

@caguero caguero commented Sep 26, 2024

🦟 Bug fix

Fixes #147

According to the spdlog notes about location flags, when using source location flags it's necessary to define this compiler flag:

#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE

and then, use the SPDLOG_LOGGER_XXX() macros. This patch adds the #define and updates the example.

Without this patch:

(2024-09-26 19:53:49.435) [info] [:] info
(2024-09-26 19:53:49.435) [warning] [:] warn
(2024-09-26 19:53:49.435) [error] [:] error
(2024-09-26 19:53:49.435) [critical] [:] critical

With this patch:

(2024-09-26 19:52:52.543) [info] [main.cc:34] info
(2024-09-26 19:52:52.543) [warning] [main.cc:35] warn
(2024-09-26 19:52:52.543) [error] [main.cc:36] error
(2024-09-26 19:52:52.543) [critical] [main.cc:37] critical

Summary

Checklist

  • Signed all commits for DCO
  • Added tests
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Signed-off-by: Carlos Agüero <[email protected]>
Signed-off-by: Carlos Agüero <[email protected]>
@caguero caguero requested a review from azeey as a code owner September 26, 2024 17:55
@caguero caguero changed the title Caguero/ionic/log example source location Fix logging source location Sep 26, 2024
@azeey
Copy link
Contributor

azeey commented Sep 26, 2024

I'm surprised that the source location works for gz* macros (fix in #144), but not when using spdlog directly. Are we doing something different for our macros?

@caguero
Copy link
Contributor Author

caguero commented Sep 26, 2024

I'm surprised that the source location works for gz* macros (fix in #144), but not when using spdlog directly. Are we doing something different for our macros?

Yes, we are doing something different in the gz* macros. We're explicitly passing __FILE__ and __LINE__ in the macro. With this change that shouldn't be necessary.
https://github.com/gazebosim/gz-common/blob/gz-common6/include/gz/common/Console.hh#L67-L68

This version should be the equivalent to what we do in gz-common but I think it's more elegant what I'm proposing here. In any case both options are compatible.

Signed-off-by: Carlos Agüero <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Inbox
Development

Successfully merging this pull request may close these issues.

Empty file/line when logging
2 participants