tools: use Log instead of fmt::print

Since fmt::print does not flush the buffer, I added a Log macro to
ensure the output is immediately flushed.
Not needed for print on stderr as std lib already flush it.

Change-Id: Ieb7c04f9f191f1982643b005fae2d4e944a3a1fa
diff --git a/tools/dnc/dnc.cpp b/tools/dnc/dnc.cpp
index 86bb159..18860ae 100644
--- a/tools/dnc/dnc.cpp
+++ b/tools/dnc/dnc.cpp
@@ -127,7 +127,7 @@
             auto it = authorized_services.find(ip);
             if (it == authorized_services.end()) {
                 // Reject the connection if the ip is not authorized
-                fmt::print("Rejecting connection to {}:{}", ip, port);
+                Log("Rejecting connection to {}:{}", ip, port);
                 return false;
             }
 
@@ -135,10 +135,10 @@
             const auto &ports = it->second;
             if (std::find(ports.begin(), ports.end(), port) == ports.end()) {
                 // Reject the connection if the port is not authorized
-                fmt::print("Rejecting connection to {}:{}", ip, port);
+                Log("Rejecting connection to {}:{}", ip, port);
                 return false;
             }
-            fmt::print("Accepting connection to {}:{}", ip, port);
+            Log("Accepting connection to {}:{}", ip, port);
             return true;
         });
 
@@ -151,7 +151,7 @@
         }
         try {
             auto parsedName = parseName(name);
-            fmt::print("Connecting to {}:{}", parsedName.first, parsedName.second);
+            Log("Connecting to {}:{}", parsedName.first, parsedName.second);
 
             asio::ip::tcp::resolver resolver(*ioContext);
             asio::ip::tcp::resolver::results_type endpoints = resolver.resolve(parsedName.first,
@@ -167,7 +167,7 @@
                 [this, socket, mtlxSocket](const std::error_code& error,
                                            const asio::ip::tcp::endpoint& ep) {
                     if (!error) {
-                        fmt::print("Connected!\n");
+                        Log("Connected!\n");
                         mtlxSocket->setOnRecv([socket, this](const uint8_t* data, size_t size) {
                             auto data_copy = std::make_shared<std::vector<uint8_t>>(data,
                                                                                     data + size);
@@ -176,7 +176,7 @@
                                               [data_copy, this](const std::error_code& error,
                                                                 std::size_t bytesWritten) {
                                                   if (error) {
-                                                    fmt::print("Write error: {}\n", error.message());
+                                                    Log("Write error: {}\n", error.message());
                                                   }
 
                                               });
@@ -186,13 +186,13 @@
                         auto buffer = std::make_shared<std::vector<uint8_t>>(BUFFER_SIZE);
                         readFromPipe(mtlxSocket, socket, buffer);
                     } else {
-                        fmt::print("Connection error: {}\n", error.message());
+                        Log("Connection error: {}\n", error.message());
                         mtlxSocket->shutdown();
                     }
                 });
 
         } catch (std::exception& e) {
-            fmt::print("Exception: {}\n", e.what());
+            Log("Exception: {}\n", e.what());
         }
     });
 }
@@ -211,7 +211,7 @@
 {
     std::condition_variable cv;
     auto name = fmt::format("nc://{:s}:{:d}", remote_host, remote_port);
-    fmt::print("Requesting socket: %s\n", name.c_str());
+    Log("Requesting socket: %s\n", name.c_str());
     connectionManager->connectDevice(
         peer_id, name, [&](std::shared_ptr<ChannelSocket> socket, const dht::InfoHash&) {
             if (socket) {
@@ -230,7 +230,7 @@
                 readFromPipe(socket, stdinPipe, buffer);
 
                 socket->onShutdown([this]() {
-                    fmt::print("Exit program\n");
+                    Log("Exit program\n");
                     ioContext->stop();
                 });
             }
@@ -238,7 +238,7 @@
 
     connectionManager->onConnectionReady(
         [&](const DeviceId&, const std::string& name, std::shared_ptr<ChannelSocket> mtlxSocket) {
-            fmt::print("Connected!\n");
+            Log("Connected!\n");
         });
 }
 
diff --git a/tools/dnc/main.cpp b/tools/dnc/main.cpp
index cf98945..2e4d1bf 100644
--- a/tools/dnc/main.cpp
+++ b/tools/dnc/main.cpp
@@ -145,7 +145,7 @@
 
     // extract values from dnc yaml file
     if (!params.configuration.empty()) {
-        printf("read configuration file: %s\n", params.configuration.c_str());
+        Log("Read configuration file: {}\n", params.configuration.c_str());
         std::ifstream config_file(params.configuration);
         if (!config_file.is_open()) {
             std::cerr << "Error: Could not open configuration file.\n";
@@ -217,7 +217,7 @@
 
     pj_log_set_level(level);
     pj_log_set_log_func([](int level, const char* data, int len) {
-        fmt::print("{}", std::string_view(data, len));
+        Log("{}", std::string_view(data, len));
     });
 }
 
@@ -228,7 +228,7 @@
     auto params = parse_args(argc, argv);
 
     if (params.help) {
-        fmt::print("Usage: dnc [options] [PEER_ID]\n"
+        Log("Usage: dnc [options] [PEER_ID]\n"
                    "\nOptions:\n"
                    "  -h, --help                  Show this help message and exit.\n"
                    "  -v, --version               Display the program version.\n"
@@ -249,7 +249,7 @@
     }
 
     if (params.version) {
-        fmt::print("dnc v1.0\n");
+        Log("dnc v1.0\n");
         return EXIT_SUCCESS;
     }
 
@@ -258,9 +258,9 @@
         fmt::print(stderr, "Hint: To generate new identity files, run: dhtnet-crtmgr --interactive\n");
         return EXIT_FAILURE;
     }
-    fmt::print("Loaded identity: {}\n", identity.second->getId());
+    Log("Loaded identity: {}\n", identity.second->getId());
 
-    fmt::print("dnc 1.0\n");
+    Log("dnc 1.0\n");
     std::unique_ptr<dhtnet::Dnc> dhtnc;
     if (params.listen) {
         // create dnc instance