control: Dump flight recorder to a JSON file

A future commit will dump more debug data as opposed to just the flight
recorder.  To better support the data all being in the same file, it
will be a JSON file.  The first step of that is to write the flight
recorder output to a JSON file.

This also reorganizes the Manager code that does it to prepare for
different data also being in the same file.

An example is:
{
    "flight_recorder": [
        "Oct 06 05:59:01.183998: main: Startup"
    ]
}

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Iaeb55ffde3a30c2345968e1b3fad313b50aff331
diff --git a/control/main.cpp b/control/main.cpp
index ba9c612..5e81e99 100644
--- a/control/main.cpp
+++ b/control/main.cpp
@@ -31,9 +31,21 @@
 #include <sdeventplus/source/signal.hpp>
 #include <stdplus/signal.hpp>
 
+#include <fstream>
+
 using namespace phosphor::fan::control;
 using namespace phosphor::logging;
 
+#ifdef CONTROL_USE_JSON
+void dumpFlightRecorder()
+{
+    nlohmann::json data;
+    phosphor::fan::control::json::FlightRecorder::instance().dump(data);
+    std::ofstream file{json::Manager::dumpFile};
+    file << std::setw(4) << data;
+}
+#endif
+
 int main(int argc, char* argv[])
 {
     auto event = phosphor::fan::util::SDEventPlus::getEvent();
@@ -135,7 +147,7 @@
 #ifdef CONTROL_USE_JSON
         phosphor::fan::control::json::FlightRecorder::instance().log(
             "main", "Unexpected exception exit");
-        phosphor::fan::control::json::FlightRecorder::instance().dump();
+        dumpFlightRecorder();
 #endif
         throw;
     }
@@ -143,7 +155,7 @@
 #ifdef CONTROL_USE_JSON
     phosphor::fan::control::json::FlightRecorder::instance().log(
         "main", "Abnormal exit");
-    phosphor::fan::control::json::FlightRecorder::instance().dump();
+    dumpFlightRecorder();
 #endif
 
     return 1;