Adding multiple logging outputs
A good way to validate that a design works with multiple scenarios is to implement solutions for each scenario. We have a common Output
interface class that defines two methods, clone
and sendLine
, and we need to make sure this interface will work for sending log messages to a log file and to the console.
Let’s start with a class called FileOutput
that inherits from Output
. The new class goes in Log.h
right after the getOutputs
and the addLogOutput
functions, like this:
class FileOutput : public Output
{
public:
FileOutput (std::string_view dir)
: mOutputDir(dir),
mFileNamePattern("{}"),
mMaxSize(0),
mRolloverCount(0)
{ }
FileOutput (FileOutput const & rhs)
: mOutputDir(rhs.mOutputDir),
mFileNamePattern(rhs.mFileNamePattern...