Add ability to write log to abstract log sink
It completely decouples log writing and file system.
Change-Id: Iae3b881826e04500f4862a16c237e0f7c37c9536
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
Signed-off-by: Alexei Strots <alexei.strots@bluerivertech.com>
diff --git a/aos/events/logging/logfile_utils.h b/aos/events/logging/logfile_utils.h
index c75c8fb..8415efe 100644
--- a/aos/events/logging/logfile_utils.h
+++ b/aos/events/logging/logfile_utils.h
@@ -51,7 +51,7 @@
// Marker struct for one of our constructor overloads.
struct already_out_of_space_t {};
- DetachedBufferWriter(std::unique_ptr<FileHandler> file_handler,
+ DetachedBufferWriter(std::unique_ptr<LogSink> log_sink,
std::unique_ptr<DataEncoder> encoder);
// Creates a dummy instance which won't even open a file. It will act as if
// opening the file ran out of space immediately.
@@ -64,11 +64,11 @@
DetachedBufferWriter &operator=(DetachedBufferWriter &&other);
DetachedBufferWriter &operator=(const DetachedBufferWriter &) = delete;
- std::string_view filename() const { return file_handler_->filename(); }
+ std::string_view name() const { return log_sink_->name(); }
// This will be true until Close() is called, unless the file couldn't be
// created due to running out of space.
- bool is_open() const { return file_handler_->is_open(); }
+ bool is_open() const { return log_sink_->is_open(); }
// Queues up a finished FlatBufferBuilder to be encoded and written.
//
@@ -106,7 +106,7 @@
return encoder_->total_bytes();
}
- WriteStats* WriteStatistics() const { return file_handler_->WriteStatistics(); }
+ WriteStats *WriteStatistics() const { return log_sink_->WriteStatistics(); }
private:
// Performs a single writev call with as much of the data we have queued up as
@@ -124,7 +124,7 @@
// the current time. It just needs to be close.
void FlushAtThreshold(aos::monotonic_clock::time_point now);
- std::unique_ptr<FileHandler> file_handler_;
+ std::unique_ptr<LogSink> log_sink_;
std::unique_ptr<DataEncoder> encoder_;
bool ran_out_of_space_ = false;