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

Merged
merged 7 commits into from
Oct 8, 2024

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 <caguero@openrobotics.org>
Signed-off-by: Carlos Agüero <caguero@openrobotics.org>
Signed-off-by: Carlos Agüero <caguero@openrobotics.org>
@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 <caguero@openrobotics.org>
iche033
iche033 previously approved these changes Oct 7, 2024
Copy link
Contributor

@iche033 iche033 left a comment

Choose a reason for hiding this comment

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

tested and confirmed that the example now prints out source file name and line no.

Signed-off-by: Carlos Agüero <caguero@openrobotics.org>
@iche033
Copy link
Contributor

iche033 commented Oct 8, 2024

windows caught a compile error:

C:\J\workspace\gz_utils-pr-win\ws\gz-utils\log\src\Logger_TEST.cc(146,35): error C2664: 'void gz::utils::log::v3::Logger::SetLogDestination(const std::string &)': cannot convert argument 1 from 'std::filesystem::path' to 'const std::string &' [C:\J\workspace\gz_utils-pr-win\ws\build\gz-utils3\log\src\UNIT_Logger_TEST.vcxproj]

@iche033 iche033 dismissed their stale review October 8, 2024 01:12

windows CI caught compile error

Signed-off-by: Ian Chen <ichen@openrobotics.org>
@iche033
Copy link
Contributor

iche033 commented Oct 8, 2024

windows caught a compile error:

C:\J\workspace\gz_utils-pr-win\ws\gz-utils\log\src\Logger_TEST.cc(146,35): error C2664: 'void gz::utils::log::v3::Logger::SetLogDestination(const std::string &)': cannot convert argument 1 from 'std::filesystem::path' to 'const std::string &' [C:\J\workspace\gz_utils-pr-win\ws\build\gz-utils3\log\src\UNIT_Logger_TEST.vcxproj]

testing fix: b94745f

@iche033 iche033 merged commit 2aa20d7 into gz-utils3 Oct 8, 2024
12 checks passed
@iche033 iche033 deleted the caguero/ionic/log_example_source_location branch October 8, 2024 18:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Empty file/line when logging
3 participants