print: Cleanup std::cerr/cout with stdplus::print

This allow us to migrate to std::print once that is supported by gcc.

Change-Id: I9b4157acca3e75903046377d030e4ac4f5232ffb
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/src/blobtool.cpp b/src/blobtool.cpp
index ac29abd..2f45aab 100644
--- a/src/blobtool.cpp
+++ b/src/blobtool.cpp
@@ -6,8 +6,8 @@
 
 #include <algorithm>
 #include <fstream>
-#include <iostream>
 #include <nlohmann/json.hpp>
+#include <stdplus/print.hpp>
 
 constexpr auto defaultBlobConfigPath = "/usr/share/binaryblob/config.json";
 
@@ -28,21 +28,21 @@
 
 void printUsage(const BlobToolConfig& cfg)
 {
-    std::cout
-        << "Usage: \n"
-        << cfg.programName << " [OPTIONS]\n"
-        << "\t--list\t\tList all supported blobs. This is a default.\n"
-        << "\t--read\t\tRead blob specified in --blob argument"
-           " (which becomes mandatory).\n"
-        << "\t--config\tFILENAME\tPath to the configuration file. The default "
-           "is /usr/share/binaryblob/config.json.\n"
-        << "\t--binary-store\tFILENAME\tPath to the binary storage. If "
-           "specified,"
-           "configuration file is not used.\n"
-        << "\t--blob\tSTRING\tThe name of the blob to read.\n"
-        << "\t--offset\tNUMBER\tThe offset in the binary store file, where"
-           " the binary store actually starts.\n"
-        << "\t--help\t\tPrint this help and exit\n";
+    stdplus::print(stderr,
+                   "Usage: \n"
+                   "{} [OPTIONS]\n"
+                   "\t--list\t\tList all supported blobs. This is a default.\n"
+                   "\t--read\t\tRead blob specified in --blob argument (which "
+                   "becomes mandatory).\n"
+                   "\t--config\tFILENAME\tPath to the configuration file. The "
+                   "default is /usr/share/binaryblob/config.json.\n"
+                   "\t--binary-store\tFILENAME\tPath to the binary storage. If "
+                   "specified, configuration file is not used.\n"
+                   "\t--blob\tSTRING\tThe name of the blob to read.\n"
+                   "\t--offset\tNUMBER\tThe offset in the binary store file, "
+                   "where the binary store actually starts.\n"
+                   "\t--help\t\tPrint this help and exit\n",
+                   cfg.programName);
 }
 
 bool parseOptions(int argc, char* argv[], BlobToolConfig& cfg)
@@ -118,8 +118,8 @@
             toolConfig.binStore, toolConfig.offsetBytes);
         if (!file)
         {
-            std::cerr << "Can't open binary store " << toolConfig.binStore
-                      << std::endl;
+            stdplus::print(stderr, "Can't open binary store {}\n",
+                           toolConfig.binStore);
             printUsage(toolConfig);
             return 1;
         }
@@ -135,8 +135,8 @@
 
         if (!input.good())
         {
-            std::cerr << "Config file not found: " << toolConfig.configPath
-                      << std::endl;
+            stdplus::print(stderr, "Config file not found:{}\n",
+                           toolConfig.configPath);
             return 1;
         }
 
@@ -146,8 +146,8 @@
         }
         catch (const std::exception& e)
         {
-            std::cerr << "Failed to parse config into json: " << std::endl
-                      << e.what() << std::endl;
+            stdplus::print(stderr, "Failed to parse config into json:\n{}\n",
+                           e.what());
             return 1;
         }
 
@@ -160,9 +160,9 @@
             }
             catch (const std::exception& e)
             {
-                std::cerr << "Encountered error when parsing config file:"
-                          << std::endl
-                          << e.what() << std::endl;
+                stdplus::print(
+                    stderr, "Encountered error when parsing config file:\n{}\n",
+                    e.what());
                 return 1;
             }
 
@@ -177,7 +177,7 @@
 
     if (toolConfig.action == BlobToolConfig::Action::LIST)
     {
-        std::cout << "Supported Blobs: " << std::endl;
+        stdplus::print(stderr, "Supported Blobs: \n");
         for (const auto& store : stores)
         {
             const auto blobIds = store->getBlobIds();
@@ -190,8 +190,8 @@
     {
         if (toolConfig.blobName.empty())
         {
-            std::cerr << "Must specify the name of the blob to read."
-                      << std::endl;
+            stdplus::print(stderr,
+                           "Must specify the name of the blob to read.\n");
             printUsage(toolConfig);
             return 1;
         }
@@ -209,8 +209,8 @@
                 const auto blobData = store->readBlob(toolConfig.blobName);
                 if (blobData.empty())
                 {
-                    std::cerr << "No data read from " << store->getBaseBlobId()
-                              << std::endl;
+                    stdplus::print(stderr, "No data read from {}\n",
+                                   store->getBaseBlobId());
                     continue;
                 }
 
@@ -228,8 +228,7 @@
 
         if (!blobFound)
         {
-            std::cerr << "Blob " << toolConfig.blobName << " not found."
-                      << std::endl;
+            stdplus::print(stderr, "Blob {} not found.\n", toolConfig.blobName);
             return 1;
         }
     }
diff --git a/src/meson.build b/src/meson.build
index 877ef83..0e20dcd 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -3,6 +3,7 @@
   dependencies: [
     dependency('phosphor-ipmi-blobs'),
     dependency('phosphor-logging'),
+    dependency('stdplus'),
     binaryblobproto_dep,
   ])
 
diff --git a/test/binarystore_unittest.cpp b/test/binarystore_unittest.cpp
index f7c8a8e..5d82f81 100644
--- a/test/binarystore_unittest.cpp
+++ b/test/binarystore_unittest.cpp
@@ -53,14 +53,13 @@
 
     size_t readToBuf(size_t pos, size_t count, char* buf) const override
     {
-        std::cout << "Read " << count << " bytes at " << pos << std::endl;
+        stdplus::print(stderr, "Read {} bytes at {}\n", count, pos);
         return data_->copy(buf, count, pos);
     }
 
     std::string readAsStr(size_t pos, size_t count) const override
     {
-        std::cout << "Read as str " << count << " bytes at " << pos
-                  << std::endl;
+        stdplus::print(stderr, "Read as str {} bytes at {}\n", count, pos);
         return data_->substr(pos, count);
     }