Provide simulation log writer in aos/util

I'd been copy-pasting the same code for all my simulation logging needs.

Change-Id: Id82714f2f0ab12f0078b73b625bf5099b433d656
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/y2023/localizer/localizer_replay.cc b/y2023/localizer/localizer_replay.cc
index c74b708..27f0d18 100644
--- a/y2023/localizer/localizer_replay.cc
+++ b/y2023/localizer/localizer_replay.cc
@@ -5,9 +5,10 @@
 #include "aos/init.h"
 #include "aos/json_to_flatbuffer.h"
 #include "aos/network/team_number.h"
-#include "y2023/localizer/localizer.h"
+#include "aos/util/simulation_logger.h"
 #include "gflags/gflags.h"
 #include "y2023/control_loops/drivetrain/drivetrain_base.h"
+#include "y2023/localizer/localizer.h"
 
 DEFINE_string(config, "y2023/aos_config.json",
               "Name of the config file to replay using.");
@@ -15,27 +16,6 @@
 DEFINE_string(output_folder, "/tmp/replayed",
               "Name of the folder to write replayed logs to.");
 
-class LoggerState {
- public:
-  LoggerState(aos::logger::LogReader *reader, const aos::Node *node)
-      : event_loop_(
-            reader->event_loop_factory()->MakeEventLoop("logger", node)),
-        namer_(std::make_unique<aos::logger::MultiNodeFilesLogNamer>(
-            absl::StrCat(FLAGS_output_folder, "/", node->name()->string_view(),
-                         "/"),
-            event_loop_.get())),
-        logger_(std::make_unique<aos::logger::Logger>(event_loop_.get())) {
-    event_loop_->SkipTimingReport();
-    event_loop_->SkipAosLog();
-    event_loop_->OnRun([this]() { logger_->StartLogging(std::move(namer_)); });
-  }
-
- private:
-  std::unique_ptr<aos::EventLoop> event_loop_;
-  std::unique_ptr<aos::logger::LogNamer> namer_;
-  std::unique_ptr<aos::logger::Logger> logger_;
-};
-
 int main(int argc, char **argv) {
   aos::InitGoogle(&argc, &argv);
 
@@ -69,15 +49,13 @@
 
   reader.Register(factory.get());
 
-  std::vector<std::unique_ptr<LoggerState>> loggers;
   // List of nodes to create loggers for (note: currently just roborio; this
   // code was refactored to allow easily adding new loggers to accommodate
   // debugging and potential future changes).
   const std::vector<std::string> nodes_to_log = {"imu"};
-  for (const std::string &node : nodes_to_log) {
-    loggers.emplace_back(std::make_unique<LoggerState>(
-        &reader, aos::configuration::GetNode(reader.configuration(), node)));
-  }
+  std::vector<std::unique_ptr<aos::util::LoggerState>> loggers =
+      aos::util::MakeLoggersForNodes(reader.event_loop_factory(), nodes_to_log,
+                                     FLAGS_output_folder);
 
   const aos::Node *node = nullptr;
   if (aos::configuration::MultiNode(reader.configuration())) {