Introduce `LogOutput` abstraction.
Closed this issue · 0 comments
miladHakimi commented
After an EventLogger
converts an Event
to a string, it should write it to the output (Issue: #69 ). The output could be a file, standard output, or a string (for testing). LogOutput
is the object that takes care of writing to the output and exposes the LogLine()
method. Since the underlying file might be shared among multiple threads, LogLine()
must be synchronized to make sure the logs do not get corrupted.
A sample implementation:
class Logoutput {
public:
virtual void LogLine(const std::string &line) = 0;
};
class FileOutput : public LogOutput {
public:
void LogLine(const std::string &line) override { ... }
private:
FILE *out_ = nullptr;
};
class StringOutput: public LogOutput {
public:
void LogLine(const std::string &line) override { ... }
const std::string &GetLog() { return out_; }
private:
std::string out_ = "";
};