-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
use std::source_location and replace macros with constexpr functions #1823
Comments
Experimental PR was closed and revealed the following issues:
So overall I wouldn't know how to add std::source_location to this project without disrupting the existing design. |
I think we should at least replace spdlog::source_loc by std::source_location when it's available, to make consumption from C++20 nicer. |
#define fl_debug(...) log(spdlog::source_loc{FILE, LINE, static_cast<const char *>(FUNCTION)}, spdlog::level::trace, VA_ARGS) Just using the above gives you the option of not using SPDLOG_DEBUG to see filename:line# without changing anything in the current code base. You get individual loggers, not just the default, with the file number, line number, handy in development when you want console output to link to the source code. I went a bit further and changed the existing level function names in spdlog.h and logger.h for my own use. Plus some dereferencing the pointer to give me an easy syntax logger.debug("my message"); That part could probably be made configurable, and is just syntactic sugar. But getting back to the marco above, perhaps you could consider offering that in an example, or footnote to the formatting table for %s and %#. |
I'm very much still in the process of learning and have started writing my own version of a logging library inspired by this one; when I went to add a source flag with some enum flags to use as specifiers, I ran into this issue for getting accurate call sites until I came across this post on SO ( https://stackoverflow.com/a/66402319/11410972 ). In a tight loop of 1,000,000 iterations, the CPU cycles used to store the message and the |
c++ 20 added std::source_location which provides the current file, line, collumn and function name. as I understand the SPDLOG_info ... macros are only needed to get this informations, so it would be nice to replace the macros with constexpr functions for c++ 20 code (std::source_location is currently supported on gcc trunk)
The text was updated successfully, but these errors were encountered: