Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce LogOutput abstraction. #116

Closed
miladHakimi opened this issue Nov 8, 2022 · 0 comments · Fixed by #117
Closed

Introduce LogOutput abstraction. #116

miladHakimi opened this issue Nov 8, 2022 · 0 comments · Fixed by #117

Comments

@miladHakimi
Copy link
Contributor

miladHakimi commented Nov 8, 2022

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_ = "";
};
kuhar pushed a commit that referenced this issue Nov 15, 2022
This class provides an abstraction over the output. All the subclasses
must implement `LogLine()` method which receives a string and writes it
to the output.

This PR also contains 2 implementations of `LogOutput`class.
`FileOutput` handles writing into a file and standard output.
`StringOutput` writes to a string and is used for testing.

Fixes: #116
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant