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

Feature | Adds std::string_view overloads for logger accessor #3023

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

BenLeadbetter
Copy link
Contributor

Adds std::string_view overloads for logger accessor

Motivation

For clients who store logger ids as string literals, or other non-std::string data types, it would be very useful to add a std::string_view overload for the spdlog::get function. This would save such clients needing to make a temporary, dynamically allocated copy of their logger name data in order to access a specific logger.

Details

Only enabled in C++17

std::string_view is a C++17 feature, so the additional overloads are only included if the project is compiled against C++17 or greater.

Additional const char* overload

With the addition of the spdlog::get(std::string_view) overload, calls to this function with a const char* become ambiguous.

const char *const name = "my_logger";
spdlog::get(name); // error: call to spdlog::get is ambiguous.

To disambiguate we also add a spdlog::get(const char*) overload which forwards calls on to the spdlog::get(std::string_view) overload.

@BenLeadbetter BenLeadbetter force-pushed the feature/string-view-logger-access branch from c383778 to a3e5684 Compare February 25, 2024 08:31
include/spdlog/details/registry-inl.h Outdated Show resolved Hide resolved
@BenLeadbetter BenLeadbetter force-pushed the feature/string-view-logger-access branch from a3e5684 to da7788a Compare February 26, 2024 07:26
@BenLeadbetter
Copy link
Contributor Author

@gabime Any idea what's happening with this gcc 7 check? Looks like a git error?

@gabime gabime merged commit 5532231 into gabime:v1.x Feb 29, 2024
7 of 8 checks passed
@gabime
Copy link
Owner

gabime commented Feb 29, 2024

Merged. Thanks. The gcc 7 is a git workflow issue indeed

gabime added a commit that referenced this pull request Mar 16, 2024
gabime added a commit that referenced this pull request Apr 30, 2024
@gabime
Copy link
Owner

gabime commented Apr 30, 2024

@BenLeadbetter I had to revert this since it caused backward compatabilty problems for c++17 that links to spdlog that compiled with c++11. See #3081

@BenLeadbetter
Copy link
Contributor Author

Ah, that's a shame.

Fortunately the project for which the feature was intended went in a different direction in terms of it's spdlog integration.

In case you're interested, we had issues with the mutex locking in the registry on calls to splog::get, so we ended up writing a custom non-blocking registry for our loggers.

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.

2 participants