-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
remove constexpr on level_string_views to fix compilation on C++17 fr… #1889
Conversation
…om addition of set_string_view
@gabime Please merge this, spdlog is not usable in C++17 without it ;) Thanks in advance! |
will release new version |
Hi, this removes the constexpr declaration for log levels, which re-adds the problems caused in issue #1791. Static initialization will now cause problems again, now that the level names are not initialized reliably before entering I cannot see the utility in saving a bit of compilation time while changing the log levels (which was the feature that caused the removal of @gabime even then if people want this, a compile option be added to choose between either constexpr log levels vs the ability to change them at runtime? |
Sounds right. But what about pre cpp 17 ? |
for pre cpp 17, we can't declare |
This means this option should be offered only if cpp17 or newer is detected. PR is welcome. |
yes, that's correct. I will take a look how it can be done, maybe in cmake. |
I am fine with a compile-time option for c++17 and beyond. it is still better than it was before, where I had to patch the spdlog package in order to change the strings. |
@stevenlunt can you elaborate on what do you mean by "patching the package"? If you use spdlog as header only lib, you only have define I cannot see the real use for setting the level names in a function in c++ code, when you should not be changing them often anyway. |
i've tried updating the recipe to allow you to pass an option with the level names but it is very difficult if not impossible to convince CMake to define something like { "trace", "dbg", ... It would be better if rather than one preprocessor token there were instead separate tokens for each level string. this way it would be much more straightforward to override one or more of them |
I just tested once with cmake command line and this works fine for me cmake . -DSPDLOG_LEVEL_NAMES='{'\"mytrace\",\"mydebug\",\"myinfo\",\"mywarn\",\"mycritical\",\"myerror\",\"myoff\"'}' in my CMakeLists I added add_subdirectory(./path/to/spdlog spdlog)
if(SPDLOG_LEVEL_NAMES)
target_compile_definitions(spdlog PUBLIC SPDLOG_LEVEL_NAMES=${SPDLOG_LEVEL_NAMES})
endif() The lines after But you are right that if there was a token for each level it would look better. |
i was trying to pass options to conan create, something like: conan create . 1.8.5@third-party/stable -o spdlog:level_name_debug=DBG -o spdlog:level_name_info=INF -o spdlog:level_name_warning=WRN -o spdlog:level_name_error=ERR |
I have not used conan options before, would these then be passed through as CMake variables from conan? |
it does not seem possible through conan options to pass a macro through to gcc like {"string","string",...} |
would something like this help perhaps? |
i will create a new pull request to revert my changes from this PR and add separate string #defines for the individual level names |
…om addition of set_string_view