Save the Logger output as plain text, not JSON

This file is sent in when an event log is created to be used as FFDC.
The output is smaller and also slightly easier to read when it is in a
text file of the form:  <timestamp>: <messsage>.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I5e9953f150cc1478251f3e2131e8b3e548ed1274
diff --git a/logger.hpp b/logger.hpp
index f31ff36..51e2b80 100644
--- a/logger.hpp
+++ b/logger.hpp
@@ -1,5 +1,7 @@
 #pragma once
 
+#include "utility.hpp"
+
 #include <fmt/format.h>
 #include <unistd.h>
 
@@ -110,7 +112,7 @@
     }
 
     /**
-     * @brief Writes the JSON to a temporary file and returns the path
+     * @brief Writes the data to a temporary file and returns the path
      *        to it.
      *
      * Uses a temp file because the only use case for this is for sending
@@ -124,27 +126,26 @@
         using namespace std::literals::string_literals;
 
         char tmpFile[] = "/tmp/loggertemp.XXXXXX";
-        int fd = mkstemp(tmpFile);
-        if (fd == -1)
+        util::FileDescriptor fd{mkstemp(tmpFile)};
+        if (fd() == -1)
         {
             throw std::runtime_error{"mkstemp failed!"};
         }
 
         std::filesystem::path path{tmpFile};
 
-        nlohmann::json data;
-        data["Logs"] = _entries;
-        auto jsonString = data.dump();
-
-        auto rc = write(fd, jsonString.c_str(), jsonString.size());
-        auto e = errno;
-        close(fd);
-        if (rc == 0)
+        for (const auto& [time, message] : _entries)
         {
-            log(fmt::format("Could not write to temp file {} errno {}", tmpFile,
-                            e),
-                Logger::error);
-            throw std::runtime_error{"Could not write to "s + path.string()};
+            auto line = fmt::format("{}: {}\n", time, message);
+            auto rc = write(fd(), line.data(), line.size());
+            if (rc == -1)
+            {
+                auto e = errno;
+                auto msg = fmt::format(
+                    "Could not write to temp file {} errno {}", tmpFile, e);
+                log(msg, Logger::error);
+                throw std::runtime_error{msg};
+            }
         }
 
         return std::filesystem::path{tmpFile};
diff --git a/presence/error_reporter.cpp b/presence/error_reporter.cpp
index 4644535..f1dfaa9 100644
--- a/presence/error_reporter.cpp
+++ b/presence/error_reporter.cpp
@@ -160,7 +160,7 @@
             sdbusplus::xyz::openbmc_project::Logging::server::Entry::Level::
                 Error);
 
-    // Save our logs in JSON to a temp file and get the file descriptor
+    // Save our logs to a temp file and get the file descriptor
     // so it can be passed in as FFDC data.
     auto logFile = getLogger().saveToTempFile();
     util::FileDescriptor fd{-1};
@@ -172,7 +172,7 @@
         ffdc;
 
     ffdc.emplace_back(sdbusplus::xyz::openbmc_project::Logging::server::Create::
-                          FFDCFormat::JSON,
+                          FFDCFormat::Text,
                       0x01, 0x01, fd());
 
     try
diff --git a/test/logger_test.cpp b/test/logger_test.cpp
index c234b4f..1a70b26 100644
--- a/test/logger_test.cpp
+++ b/test/logger_test.cpp
@@ -45,12 +45,6 @@
 
     auto path = logger.saveToTempFile();
     ASSERT_TRUE(std::filesystem::exists(path));
-
-    std::ifstream file{path};
-
-    // check that valid JSON was written
-    auto newJSON = nlohmann::json::parse(file);
-    EXPECT_EQ(newJSON["Logs"].size(), logSize);
     std::filesystem::remove(path);
 
     logger.clear();