-
-
Notifications
You must be signed in to change notification settings - Fork 44
How to convert a VSFileSystem::vs_dprintf() call to the Boost logging way
Stephen G Tuggy edited this page Jul 6, 2020
·
3 revisions
- Replace the text
VSFileSystem::vs_dprintf
withBOOST_LOG_TRIVIAL
. - Change the following parentheses from wrapping the entire rest of what follows on the line, to wrapping only the log level. Said log level should be one of:
info
(for debug level 1);debug
(for debug level 2); ortrace
(for debug level 3). - After the log level and its parentheses, put
<<
, as if you were writing tocout
. - If a
printf
-style format string with args was used, replace it withboost::format(format_str) % arg1 % arg2 ...
(https://www.boost.org/doc/libs/1_73_0/libs/format/doc/format.html). Otherwise, just do a straight string literal. - If there was a
\n
at the end, be sure to remove it. The newline is implied with BOOST_LOG_TRIVIAL. - Finally, format the code nicely, being sure to indent it properly and wrap it to the next line if it gets too long.
Taking this all together:
VSFileSystem::vs_dprintf(1, "Pause key pressed\n");
becomes
BOOST_LOG_TRIVIAL(info) << "Pause key pressed";
while
VSFileSystem::vs_dprintf(3, "Player ship needs transport from %s to %s across %d systems",
locationBaseName.c_str(),
destinationSystemName.c_str(),
jumps.size());
becomes
BOOST_LOG_TRIVIAL(trace) << boost::format("Player ship needs transport from %1% to %2% across %3% systems") % locationBaseName %
destinationSystemName % jumps.size();
Note that in the last example, the .c_str()
was also removed in a couple of cases, because boost::format
is aware of C++-style strings.
Hopefully this is enough to give you the idea. Feel free to contact me (@stephengtuggy) with any questions or feedback.