I'm trying to make an elegant logging system in C++. I'm currently using printf(), although cout can also be an option.
What I want to achieve is something like this
console_log( "ClassName", "funcName", "Message." );
My current code for this is simply:
static void console_log( const std::string & className, const std::string & funcName, const std::string & message ) {
printf( "%s : %s : %s\n", className.c_str(), funcName.c_str(), message.c_str() );
}
It prints nicely, like this
// For example:
console_log( "MenuPanel", "selectedThisButton", "Something happened." );
console_log( "MenuPanel", "selectedAnotherButton", "Another thing happened." );
// Output:
MenuPanel : selectedThisButton : Something happened.
MenuPanel : selectedAnotherButton : Another thing happened.
However, I want it to be printed in a table-like manner, where all "columns" are aligned properly. For example:
MenuPanel : selectedThisButton : Something happened.
MenuPanel : selectedAnotherButton : Another thing happened.
How do I make it so that the first and second "columns" have the exact same width/number of characters, with additional spaces if necessary? It doesn't need to be dynamic. Something like setting a "column" to 16 characters will do.
I don't wish to use any third-party libs for something as simple as this, though. And if possible, no boost.
printfhas alignment operators if one should read the man page (e.g.printf( "%-16s", ... );).