Controlling what gets logged
Earlier in this chapter when we were exploring filtering options, I mentioned that we will need a custom stream class instead of returning std::fstream
from the log
function. We need this so that we don’t immediately send information to the log file. We need to avoid sending a log message directly to the log file because there could be filtering rules in place that could cause the log message to be ignored.
We also decided that we would make the decision to log or not based entirely on the default tags and any tags sent directly to the log
function. We could have the log
function make the decision and either return std::fstream
if the log message should proceed or a fake stream if the log message should be ignored, but it’s probably better to always return the same type. That seems like the simplest and most straightforward solution. Switching between stream types just seems like a more complicated solution that still requires a custom...