I'm writing a library in C++ which needs to be as fast as reasonably possible. However, I'd also like to be able to provide logging in case a user (or me) needs to debug possible problems.
This library needs to be built, but also contains some header-only templated classes.
As I understand, usually logging in libraries is done by declaring, but not defining, a specific logging function, which is used to log messages inside the library. This function is then defined inside the user's program, which logs with whatever mechanism the user wants (or doesn't log at all).
As some logs are in very performance-sensitive places, I'm wondering whether I should be concerned that this approach would impact the library performances even when no logging is desired by the user at all. The library is usually linked statically.
An alternative idea I had would be to define logging as a macro, and define it both during the library build step and during the final program build step as an either empty macro or the desired build function. This would ensure that in case of no logging, nothing would remain in the final program. However, it would be more cumbersome for the user, and possibly more complicated as one would need to modify a library header file before building the library in order to correctly define the macro.
What are the best practices for this type of problem?