Rotate image logger every minute

Forcefully split up large image logs into parts so we can get the whole
match's data.

Signed-off-by: Milind Upadhyay <milind.upadhyay@gmail.com>
Change-Id: Id6e379867cb31a634c51d16577a013ab53be579a
diff --git a/aos/events/logging/logger_main.cc b/aos/events/logging/logger_main.cc
index aa6f25b..b56f977 100644
--- a/aos/events/logging/logger_main.cc
+++ b/aos/events/logging/logger_main.cc
@@ -18,6 +18,9 @@
 
 DEFINE_bool(snappy_compress, false, "If true, compress log data using snappy.");
 
+DEFINE_double(rotate_every, 0.0,
+              "If set, rotate the logger after this many seconds");
+
 int main(int argc, char *argv[]) {
   gflags::SetUsageMessage(
       "This program provides a simple logger binary that logs all SHMEM data "
@@ -43,6 +46,20 @@
   }
 
   aos::logger::Logger logger(&event_loop);
+
+  if (FLAGS_rotate_every != 0.0) {
+    aos::monotonic_clock::time_point last_rotation_time =
+        event_loop.monotonic_now();
+    logger.set_on_logged_period([&] {
+      const auto now = event_loop.monotonic_now();
+      if (now > last_rotation_time +
+                    std::chrono::duration<double>(FLAGS_rotate_every)) {
+        logger.Rotate();
+        last_rotation_time = now;
+      }
+    });
+  }
+
   event_loop.OnRun([&log_namer, &logger]() {
     if (FLAGS_skip_renicing) {
       LOG(WARNING) << "Ignoring request to renice to -20 due to "