I currently have a logging system that takes a char* and var args and then uses them to do a printf. This works well with C-style strings, but I’d something that’s a little cleaner. Currently if I use std::stringstream I must create the stringstream outside of the logging system, and then use the char* to the string given by the stringstream. It looks something like this:
std::stringstream strStream;
strStream << "The value of x is: " << x;
logging::print( strStream.str().c_str() );
What I would like is to pass the paramaters into the function as if I was using them directly with a stringstream. Which would look something like this from the user’s point of view:
logging::printStream("The value of x is: " << x);
or possibly like this:
logging::printStream("The value of x is: ", x);
Is there any way to use logging in such a way that I can use a stringstream without having to create it outside of the logging system’s functions?
This is especially important because I intend to create a macro that prevents any of the function parameters from compiling in shipping builds. The macro will be useless if I have to create the stringstream outside of it and pass it in. Technically I could make a macro that does the stringstream stuff I’m talking about in this question, but that’s pretty messy as I won’t always be using stringstreams with this logging, so I would have a macro for the standard logging, and a different macro for using stringstreams that within it calls the macro for standard logging.
I came up with two HACK solutions, but they should work. The first doesn’t use the scope resolution operator and is safer. The second uses a noop int variable to fake out the scoping.
I updated logging__printStream to logging_printStream because of 17.6.4.3.2
I left the declaration of main alone because of 3.6.1