logging: switch to lg2

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Id62fbc10ab83a0cf94d235e1d1ea3e031295fbf5
diff --git a/activation.cpp b/activation.cpp
index f9fbf87..75a1b3a 100644
--- a/activation.cpp
+++ b/activation.cpp
@@ -9,7 +9,7 @@
 #include <boost/asio/post.hpp>
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/exception.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 #include <xyz/openbmc_project/Software/Version/error.hpp>
@@ -29,6 +29,7 @@
 
 namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
 
+PHOSPHOR_LOG2_USING;
 using namespace phosphor::logging;
 using sdbusplus::exception::SdBusError;
 using InternalFailure =
@@ -57,8 +58,7 @@
         }
         else
         {
-            log<level::ERR>("Error subscribing to systemd",
-                            entry("ERROR=%s", e.what()));
+            error("Error subscribing to systemd: {ERROR}", "ERROR", e);
         }
     }
 
@@ -75,8 +75,7 @@
     }
     catch (const SdBusError& e)
     {
-        log<level::ERR>("Error in unsubscribing from systemd signals",
-                        entry("ERROR=%s", e.what()));
+        error("Error unsubscribing from systemd signals: {ERROR}", "ERROR", e);
     }
 
     return;
@@ -219,13 +218,12 @@
 
     if (Activation::checkApplyTimeImmediate() == true)
     {
-        log<level::INFO>("Image Active. ApplyTime is immediate, "
-                         "rebooting BMC.");
+        info("Image Active and ApplyTime is immediate; rebooting BMC.");
         Activation::rebootBmc();
     }
     else
     {
-        log<level::INFO>("BMC image ready, need reboot to get activated.");
+        info("BMC image ready; need reboot to get activated.");
     }
 
     activation(softwareServer::Activation::Activations::Active);
@@ -243,8 +241,8 @@
     }
     catch (const SdBusError& e)
     {
-        log<level::ERR>("Error in Deleting image from image manager",
-                        entry("VERSIONPATH=%s", path.c_str()));
+        error("Error deleting image ({PATH}) from image manager: {ERROR}",
+              "PATH", path, "ERROR", e);
         return;
     }
 }
@@ -323,14 +321,14 @@
 
 void Activation::onVerifyFailed()
 {
-    log<level::ERR>("Error occurred during image validation");
+    error("Error occurred during image validation");
     report<InternalFailure>();
 }
 #endif
 
 void ActivationBlocksTransition::enableRebootGuard()
 {
-    log<level::INFO>("BMC image activating - BMC reboots are disabled.");
+    info("BMC image activating - BMC reboots are disabled.");
 
     auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
                                       SYSTEMD_INTERFACE, "StartUnit");
@@ -340,7 +338,7 @@
 
 void ActivationBlocksTransition::disableRebootGuard()
 {
-    log<level::INFO>("BMC activation has ended - BMC reboots are re-enabled.");
+    info("BMC activation has ended - BMC reboots are re-enabled.");
 
     auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
                                       SYSTEMD_INTERFACE, "StartUnit");
@@ -353,10 +351,9 @@
     auto service = utils::getService(bus, applyTimeObjPath, applyTimeIntf);
     if (service.empty())
     {
-        log<level::INFO>("Error getting the service name for BMC image "
-                         "ApplyTime. The BMC needs to be manually rebooted to "
-                         "complete the image activation if needed "
-                         "immediately.");
+        info("Error getting the service name for BMC image ApplyTime. "
+             "The BMC needs to be manually rebooted to complete the image "
+             "activation if needed immediately.");
     }
     else
     {
@@ -379,8 +376,7 @@
         }
         catch (const SdBusError& e)
         {
-            log<level::ERR>("Error in getting ApplyTime",
-                            entry("ERROR=%s", e.what()));
+            error("Error in getting ApplyTime: {ERROR}", "ERROR", e);
         }
     }
     return false;
@@ -399,7 +395,7 @@
     }
     catch (const SdBusError& e)
     {
-        log<level::ERR>("Error in trying to upgrade Host Bios.");
+        error("Error in trying to upgrade Host Bios: {ERROR}", "ERROR", e);
         report<InternalFailure>();
     }
 }
@@ -432,7 +428,7 @@
             // Set Activation value to active
             activation(softwareServer::Activation::Activations::Active);
 
-            log<level::INFO>("Bios upgrade completed successfully.");
+            info("Bios upgrade completed successfully.");
             parent.biosVersion->version(
                 parent.versions.find(versionId)->second->version());
 
@@ -446,7 +442,7 @@
             // Set Activation value to Failed
             activation(softwareServer::Activation::Activations::Failed);
 
-            log<level::ERR>("Bios upgrade failed.");
+            error("Bios upgrade failed.");
         }
     }
 
@@ -466,9 +462,9 @@
     }
     catch (const SdBusError& e)
     {
-        log<level::ALERT>("Error in trying to reboot the BMC. "
-                          "The BMC needs to be manually rebooted to complete "
-                          "the image activation.");
+        alert("Error in trying to reboot the BMC. The BMC needs to be manually "
+              "rebooted to complete the image activation. {ERROR}",
+              "ERROR", e);
         report<InternalFailure>();
     }
 }
diff --git a/download_manager.cpp b/download_manager.cpp
index 06f4c78..972278b 100644
--- a/download_manager.cpp
+++ b/download_manager.cpp
@@ -9,7 +9,7 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <algorithm>
 #include <filesystem>
@@ -24,6 +24,7 @@
 {
 
 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+PHOSPHOR_LOG2_USING;
 using namespace phosphor::logging;
 namespace fs = std::filesystem;
 
@@ -41,7 +42,7 @@
 
     if (fileName.empty())
     {
-        log<level::ERR>("Error FileName is empty");
+        error("Filename is empty");
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("FileName"),
                               Argument::ARGUMENT_VALUE(fileName.c_str()));
         return;
@@ -49,21 +50,20 @@
 
     if (serverAddress.empty())
     {
-        log<level::ERR>("Error ServerAddress is empty");
+        error("ServerAddress is empty");
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("ServerAddress"),
                               Argument::ARGUMENT_VALUE(serverAddress.c_str()));
         return;
     }
 
-    log<level::INFO>("Downloading via TFTP",
-                     entry("FILENAME=%s", fileName.c_str()),
-                     entry("SERVERADDRESS=%s", serverAddress.c_str()));
+    info("Downloading {PATH} via TFTP: {SERVERADDRESS}", "PATH", fileName,
+         "SERVERADDRESS", serverAddress);
 
     // Check if IMAGE DIR exists
     fs::path imgDirPath(IMG_UPLOAD_DIR);
     if (!fs::is_directory(imgDirPath))
     {
-        log<level::ERR>("Error Image Dir does not exist");
+        error("Image Dir {PATH} does not exist", "PATH", imgDirPath);
         elog<InternalFailure>();
         return;
     }
@@ -81,12 +81,13 @@
                   (std::string{IMG_UPLOAD_DIR} + '/' + fileName).c_str(),
                   (char*)0);
             // execl only returns on fail
-            log<level::ERR>("Error occurred during the TFTP call");
+            error("Error ({ERRNO}) occurred during the TFTP call", "ERRNO",
+                  errno);
             elog<InternalFailure>();
         }
         else if (nextPid < 0)
         {
-            log<level::ERR>("Error occurred during fork");
+            error("Error ({ERRNO}) occurred during fork", "ERRNO", errno);
             elog<InternalFailure>();
         }
         // do nothing as parent if all is going well
@@ -96,7 +97,7 @@
     }
     else if (pid < 0)
     {
-        log<level::ERR>("Error occurred during fork");
+        error("Error ({ERRNO}) occurred during fork", "ERRNO", errno);
         elog<InternalFailure>();
     }
     else
@@ -104,11 +105,12 @@
         int status;
         if (waitpid(pid, &status, 0) < 0)
         {
-            log<level::ERR>("waitpid error");
+            error("Error ({ERRNO}) occurred during waitpid", "ERRNO", errno);
         }
         else if (WEXITSTATUS(status) != 0)
         {
-            log<level::ERR>("failed to launch tftp");
+
+            error("Failed ({STATUS}) to launch tftp", "STATUS", status);
         }
     }
 
diff --git a/image_manager.cpp b/image_manager.cpp
index a8f8210..915a4b3 100644
--- a/image_manager.cpp
+++ b/image_manager.cpp
@@ -13,7 +13,7 @@
 
 #include <elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Software/Image/error.hpp>
 
 #include <algorithm>
@@ -28,6 +28,7 @@
 namespace manager
 {
 
+PHOSPHOR_LOG2_USING;
 using namespace phosphor::logging;
 using namespace sdbusplus::xyz::openbmc_project::Software::Image::Error;
 namespace Software = phosphor::logging::xyz::openbmc_project::Software;
@@ -75,8 +76,7 @@
 {
     if (!fs::is_regular_file(tarFilePath))
     {
-        log<level::ERR>("Error tarball does not exist",
-                        entry("FILENAME=%s", tarFilePath.c_str()));
+        error("Tarball {PATH} does not exist", "PATH", tarFilePath);
         report<ManifestFileFailure>(ManifestFail::PATH(tarFilePath.c_str()));
         return -1;
     }
@@ -88,8 +88,7 @@
     // Create a tmp dir to extract tarball.
     if (!mkdtemp(tmpDir.data()))
     {
-        log<level::ERR>("Error occurred during mkdtemp",
-                        entry("ERRNO=%d", errno));
+        error("Error ({ERRNO}) occurred during mkdtemp", "ERRNO", errno);
         report<InternalFailure>(InternalFail::FAIL("mkdtemp"));
         return -1;
     }
@@ -103,15 +102,14 @@
     auto rc = unTar(tarFilePath, tmpDirPath.string());
     if (rc < 0)
     {
-        log<level::ERR>("Error occurred during untar");
+        error("Error ({RC}) occurred during untar", "RC", rc);
         return -1;
     }
 
     // Verify the manifest file
     if (!fs::is_regular_file(manifestPath))
     {
-        log<level::ERR>("Error No manifest file",
-                        entry("FILENAME=%s", tarFilePath.c_str()));
+        error("No manifest file {PATH}", "PATH", tarFilePath);
         report<ManifestFileFailure>(ManifestFail::PATH(tarFilePath.c_str()));
         return -1;
     }
@@ -120,7 +118,8 @@
     auto version = Version::getValue(manifestPath.string(), "version");
     if (version.empty())
     {
-        log<level::ERR>("Error unable to read version from manifest file");
+        error("Unable to read version from manifest file {PATH}", "PATH",
+              tarFilePath);
         report<ManifestFileFailure>(ManifestFail::PATH(tarFilePath.c_str()));
         return -1;
     }
@@ -129,10 +128,11 @@
     std::string currMachine = Version::getBMCMachine(OS_RELEASE_FILE);
     if (currMachine.empty())
     {
-        log<level::ERR>("Failed to read machine name from osRelease",
-                        entry("FILENAME=%s", OS_RELEASE_FILE));
+        auto path = OS_RELEASE_FILE;
+        error("Failed to read machine name from osRelease: {PATH}", "PATH",
+              path);
         report<ImageFailure>(ImageFail::FAIL("Failed to read machine name"),
-                             ImageFail::PATH("OS_RELEASE_FILE"));
+                             ImageFail::PATH(path));
         return -1;
     }
 
@@ -143,9 +143,9 @@
     {
         if (machineStr != currMachine)
         {
-            log<level::ERR>("BMC upgrade: Machine name doesn't match",
-                            entry("CURR_MACHINE=%s", currMachine.c_str()),
-                            entry("NEW_MACHINE=%s", machineStr.c_str()));
+            error(
+                "BMC upgrade: Machine name doesn't match: {CURRENT_MACHINE} vs {NEW_MACHINE}",
+                "CURRENT_MACHINE", currMachine, "NEW_MACHINE", machineStr);
             report<ImageFailure>(
                 ImageFail::FAIL("Machine name does not match"),
                 ImageFail::PATH(manifestPath.string().c_str()));
@@ -154,7 +154,7 @@
     }
     else
     {
-        log<level::WARNING>("No machine name in Manifest file");
+        warning("No machine name in Manifest file");
         report<ImageFailure>(
             ImageFail::FAIL("MANIFEST is missing machine name"),
             ImageFail::PATH(manifestPath.string().c_str()));
@@ -164,21 +164,23 @@
     auto purposeString = Version::getValue(manifestPath.string(), "purpose");
     if (purposeString.empty())
     {
-        log<level::ERR>("Error unable to read purpose from manifest file");
+        error("Unable to read purpose from manifest file {PATH}", "PATH",
+              tarFilePath);
         report<ManifestFileFailure>(ManifestFail::PATH(tarFilePath.c_str()));
         return -1;
     }
 
-    auto purpose = Version::VersionPurpose::Unknown;
-    try
+    auto convertedPurpose =
+        sdbusplus::message::convert_from_string<Version::VersionPurpose>(
+            purposeString);
+
+    if (!convertedPurpose)
     {
-        purpose = Version::convertVersionPurposeFromString(purposeString);
+        error(
+            "Failed to convert manifest purpose ({PURPOSE}) to enum; setting to Unknown.",
+            "PURPOSE", purposeString);
     }
-    catch (const sdbusplus::exception::InvalidEnumString& e)
-    {
-        log<level::ERR>("Error: Failed to convert manifest purpose to enum."
-                        " Setting to Unknown.");
-    }
+    auto purpose = convertedPurpose.value_or(Version::VersionPurpose::Unknown);
 
     // Get ExtendedVersion
     std::string extendedVersion =
@@ -223,8 +225,8 @@
     }
     else
     {
-        log<level::INFO>("Software Object with the same version already exists",
-                         entry("VERSION_ID=%s", id.c_str()));
+        info("Software Object with the same version ({VERSION}) already exists",
+             "VERSION", id);
         fs::remove_all(imageDirPath);
     }
     return 0;
@@ -240,10 +242,9 @@
 
     if (it->second->isFunctional())
     {
-        log<level::ERR>(("Error: Version " + entryId +
-                         " is currently running on the BMC."
-                         " Unable to remove.")
-                            .c_str());
+        error(
+            "Version {VERSION} is currently running on the BMC; unable to remove",
+            "VERSION", entryId);
         return;
     }
 
@@ -261,19 +262,19 @@
 {
     if (tarFilePath.empty())
     {
-        log<level::ERR>("Error TarFilePath is empty");
+        error("TarFilePath is empty");
         report<UnTarFailure>(UnTarFail::PATH(tarFilePath.c_str()));
         return -1;
     }
     if (extractDirPath.empty())
     {
-        log<level::ERR>("Error ExtractDirPath is empty");
+        error("ExtractDirPath is empty");
         report<UnTarFailure>(UnTarFail::PATH(extractDirPath.c_str()));
         return -1;
     }
 
-    log<level::INFO>("Untaring", entry("FILENAME=%s", tarFilePath.c_str()),
-                     entry("EXTRACTIONDIR=%s", extractDirPath.c_str()));
+    info("Untaring {PATH} to {EXTRACTIONDIR}", "PATH", tarFilePath,
+         "EXTRACTIONDIR", extractDirPath);
     int status = 0;
     pid_t pid = fork();
 
@@ -283,8 +284,7 @@
         execl("/bin/tar", "tar", "-xf", tarFilePath.c_str(), "-C",
               extractDirPath.c_str(), (char*)0);
         // execl only returns on fail
-        log<level::ERR>("Failed to execute untar file",
-                        entry("FILENAME=%s", tarFilePath.c_str()));
+        error("Failed to execute untar on {PATH}", "PATH", tarFilePath);
         report<UnTarFailure>(UnTarFail::PATH(tarFilePath.c_str()));
         return -1;
     }
@@ -293,15 +293,15 @@
         waitpid(pid, &status, 0);
         if (WEXITSTATUS(status))
         {
-            log<level::ERR>("Failed to untar file",
-                            entry("FILENAME=%s", tarFilePath.c_str()));
+            error("Failed ({STATUS}) to untar file {PATH}", "STATUS", status,
+                  "PATH", tarFilePath);
             report<UnTarFailure>(UnTarFail::PATH(tarFilePath.c_str()));
             return -1;
         }
     }
     else
     {
-        log<level::ERR>("fork() failed.");
+        error("fork() failed: {ERRNO}", "ERRNO", errno);
         report<UnTarFailure>(UnTarFail::PATH(tarFilePath.c_str()));
         return -1;
     }
diff --git a/image_manager_main.cpp b/image_manager_main.cpp
index 7b4e18e..1aeb698 100644
--- a/image_manager_main.cpp
+++ b/image_manager_main.cpp
@@ -3,7 +3,7 @@
 #include "image_manager.hpp"
 #include "watch.hpp"
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 
 #include <cstdlib>
@@ -31,8 +31,7 @@
     }
     catch (std::exception& e)
     {
-        using namespace phosphor::logging;
-        log<level::ERR>(e.what());
+        lg2::error("Error in event loop: {ERROR}", "ERROR", e);
         return -1;
     }
 
diff --git a/image_verify.cpp b/image_verify.cpp
index 4d42b49..b7654aa 100644
--- a/image_verify.cpp
+++ b/image_verify.cpp
@@ -12,7 +12,7 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
 #include <cassert>
@@ -26,6 +26,7 @@
 namespace image
 {
 
+PHOSPHOR_LOG2_USING;
 using namespace phosphor::logging;
 using namespace phosphor::software::manager;
 using InternalFailure =
@@ -52,7 +53,7 @@
     // Find the path of all the files
     if (!fs::is_directory(signedConfPath))
     {
-        log<level::ERR>("Signed configuration path not found in the system");
+        error("Signed configuration path not found in the system");
         elog<InternalFailure>();
     }
 
@@ -131,7 +132,7 @@
         // public keys and hash on the system.
         if (false == systemLevelVerify())
         {
-            log<level::ERR>("System level Signature Validation failed");
+            error("System level Signature Validation failed");
             return false;
         }
 
@@ -185,8 +186,8 @@
                     verifyFile(file, sigFile, publicKeyFile, hashType);
                 if (!optionalImagesValid)
                 {
-                    log<level::ERR>("Image file Signature Validation failed",
-                                    entry("IMAGE=%s", optionalImage.c_str()));
+                    error("Image file Signature Validation failed on {IMAGE}",
+                          "IMAGE", optionalImage);
                     return false;
                 }
             }
@@ -194,20 +195,20 @@
 
         if (verifyFullImage() == false)
         {
-            log<level::ERR>("Image full file Signature Validation failed");
+            error("Image full file Signature Validation failed");
             return false;
         }
 
         if (!bmcFilesFound && !optionalFilesFound)
         {
-            log<level::ERR>("Unable to find files to verify");
+            error("Unable to find files to verify");
             return false;
         }
 
         // Either BMC images or optional images shall be valid
         assert(valid || optionalImagesValid);
 
-        log<level::DEBUG>("Successfully completed Signature vaildation.");
+        debug("Successfully completed Signature vaildation.");
         return true;
     }
     catch (const InternalFailure& e)
@@ -216,7 +217,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        error("Error during processing: {ERROR}", "ERROR", e);
         return false;
     }
 }
@@ -227,7 +228,7 @@
     auto keyTypes = getAvailableKeyTypesFromSystem();
     if (keyTypes.empty())
     {
-        log<level::ERR>("Missing Signature configuration data in system");
+        error("Missing Signature configuration data in system");
         elog<InternalFailure>();
     }
 
@@ -286,8 +287,8 @@
     // Check existence of the files in the system.
     if (!(fs::exists(file) && fs::exists(sigFile)))
     {
-        log<level::ERR>("Failed to find the Data or signature file.",
-                        entry("FILE=%s", file.c_str()));
+        error("Failed to find the Data or signature file {PATH}.", "PATH",
+              file);
         elog<InternalFailure>();
     }
 
@@ -295,8 +296,7 @@
     auto publicRSA = createPublicRSA(publicKey);
     if (publicRSA == nullptr)
     {
-        log<level::ERR>("Failed to create RSA",
-                        entry("FILE=%s", publicKey.c_str()));
+        error("Failed to create RSA from {PATH}", "PATH", publicKey);
         elog<InternalFailure>();
     }
 
@@ -314,8 +314,8 @@
     auto hashStruct = EVP_get_digestbyname(hashFunc.c_str());
     if (!hashStruct)
     {
-        log<level::ERR>("EVP_get_digestbynam: Unknown message digest",
-                        entry("HASH=%s", hashFunc.c_str()));
+        error("EVP_get_digestbynam: Unknown message digest: {HASH}", "HASH",
+              hashFunc);
         elog<InternalFailure>();
     }
 
@@ -324,8 +324,8 @@
 
     if (result <= 0)
     {
-        log<level::ERR>("Error occurred during EVP_DigestVerifyInit",
-                        entry("ERRCODE=%lu", ERR_get_error()));
+        error("Error ({RC}) occurred during EVP_DigestVerifyInit", "RC",
+              ERR_get_error());
         elog<InternalFailure>();
     }
 
@@ -336,8 +336,8 @@
     result = EVP_DigestVerifyUpdate(rsaVerifyCtx.get(), dataPtr(), size);
     if (result <= 0)
     {
-        log<level::ERR>("Error occurred during EVP_DigestVerifyUpdate",
-                        entry("ERRCODE=%lu", ERR_get_error()));
+        error("Error ({RC}) occurred during EVP_DigestVerifyUpdate", "RC",
+              ERR_get_error());
         elog<InternalFailure>();
     }
 
@@ -352,15 +352,15 @@
     // Check the verification result.
     if (result < 0)
     {
-        log<level::ERR>("Error occurred during EVP_DigestVerifyFinal",
-                        entry("ERRCODE=%lu", ERR_get_error()));
+        error("Error ({RC}) occurred during EVP_DigestVerifyFinal", "RC",
+              ERR_get_error());
         elog<InternalFailure>();
     }
 
     if (result == 0)
     {
-        log<level::ERR>("EVP_DigestVerifyFinal:Signature validation failed",
-                        entry("PATH=%s", sigFile.c_str()));
+        error("EVP_DigestVerifyFinal:Signature validation failed on {PATH}",
+              "PATH", sigFile);
         return false;
     }
     return true;
@@ -377,7 +377,7 @@
     BIO_MEM_Ptr keyBio(BIO_new_mem_buf(data(), -1), &::BIO_free);
     if (keyBio.get() == nullptr)
     {
-        log<level::ERR>("Failed to create new BIO Memory buffer");
+        error("Failed to create new BIO Memory buffer");
         elog<InternalFailure>();
     }
 
@@ -422,8 +422,8 @@
         auto valid = verifyFile(file, sigFile, publicKeyPath, hashType);
         if (valid == false)
         {
-            log<level::ERR>("Image file Signature Validation failed",
-                            entry("IMAGE=%s", bmcImage.c_str()));
+            error("Image file Signature Validation failed on {PATH}", "PATH",
+                  bmcImage);
             return false;
         }
     }
diff --git a/item_updater.cpp b/item_updater.cpp
index 204bbf8..6580de0 100644
--- a/item_updater.cpp
+++ b/item_updater.cpp
@@ -10,7 +10,7 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 #include <xyz/openbmc_project/Software/Image/error.hpp>
 
@@ -31,6 +31,7 @@
 namespace server = sdbusplus::xyz::openbmc_project::Software::server;
 namespace control = sdbusplus::xyz::openbmc_project::Control::server;
 
+PHOSPHOR_LOG2_USING;
 using namespace phosphor::logging;
 using namespace sdbusplus::xyz::openbmc_project::Software::Image::Error;
 using namespace phosphor::software::image;
@@ -110,8 +111,7 @@
     auto pos = path.rfind("/");
     if (pos == std::string::npos)
     {
-        log<level::ERR>("No version id found in object path",
-                        entry("OBJPATH=%s", path.c_str()));
+        error("No version id found in object path: {PATH}", "PATH", path);
         return;
     }
 
@@ -168,7 +168,7 @@
     }
     catch (const fs::filesystem_error& e)
     {
-        log<level::ERR>("Failed to prepare dir", entry("ERR=%s", e.what()));
+        error("Failed to prepare dir: {ERROR}", "ERROR", e);
         return;
     }
 
@@ -191,9 +191,7 @@
             auto osRelease = iter.path() / releaseFile.relative_path();
             if (!fs::is_regular_file(osRelease))
             {
-                log<level::ERR>(
-                    "Failed to read osRelease",
-                    entry("FILENAME=%s", osRelease.string().c_str()));
+                error("Failed to read osRelease: {PATH}", "PATH", osRelease);
 
                 // Try to get the version id from the mount directory name and
                 // call to delete it as this version may be corrupted. Dynamic
@@ -208,9 +206,8 @@
             auto version = VersionClass::getBMCVersion(osRelease);
             if (version.empty())
             {
-                log<level::ERR>(
-                    "Failed to read version from osRelease",
-                    entry("FILENAME=%s", osRelease.string().c_str()));
+                error("Failed to read version from osRelease: {PATH}", "PATH",
+                      osRelease);
 
                 // Try to delete the version, same as above if the
                 // OS_RELEASE_FILE does not exist.
@@ -294,8 +291,9 @@
                     }
                     else
                     {
-                        log<level::ERR>("Unable to restore priority from file.",
-                                        entry("VERSIONID=%s", id.c_str()));
+                        error(
+                            "Unable to restore priority from file for {VERSIONID}",
+                            "VERSIONID", id);
                     }
                 }
                 activations.find(id)->second->redundancyPriority =
@@ -326,7 +324,7 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>(e.what());
+            error("Exception during processing: {ERROR}", "ERROR", e);
         }
     }
 
@@ -342,9 +340,9 @@
     {
         if (it->second->isFunctional() && ACTIVE_BMC_MAX_ALLOWED > 1)
         {
-            log<level::ERR>("Error: Version is currently running on the BMC. "
-                            "Unable to remove.",
-                            entry("VERSIONID=%s", entryId.c_str()));
+            error(
+                "Version ({VERSIONID}) is currently running on the BMC; unable to remove.",
+                "VERSIONID", entryId);
             return;
         }
     }
@@ -358,9 +356,9 @@
     auto iteratorActivations = activations.find(entryId);
     if (iteratorActivations == activations.end())
     {
-        log<level::ERR>("Error: Failed to find version in item updater "
-                        "activations map. Unable to remove.",
-                        entry("VERSIONID=%s", entryId.c_str()));
+        error(
+            "Failed to find version ({VERSIONID}) in item updater activations map; unable to remove.",
+            "VERSIONID", entryId);
     }
     else
     {
@@ -384,9 +382,9 @@
         removeReadOnlyPartition(entryId);
         removePersistDataDirectory(entryId);
 
-        log<level::ERR>("Error: Failed to find version in item updater "
-                        "versions map. Unable to remove.",
-                        entry("VERSIONID=%s", entryId.c_str()));
+        error(
+            "Failed to find version ({VERSIONID}) in item updater versions map; unable to remove.",
+            "VERSIONID", entryId);
     }
 
     helper.clearEntry(entryId);
@@ -430,7 +428,7 @@
         valid = checkImage(filePath, imageUpdateList);
         if (!valid)
         {
-            log<level::ERR>("Failed to find the needed BMC images.");
+            error("Failed to find the needed BMC images.");
             return ItemUpdater::ActivationStatus::invalid;
         }
     }
@@ -502,7 +500,7 @@
 {
     helper.factoryReset();
 
-    log<level::INFO>("BMC factory reset will take effect upon reboot.");
+    info("BMC factory reset will take effect upon reboot.");
 }
 
 void ItemUpdater::removeReadOnlyPartition(std::string versionId)
@@ -582,7 +580,7 @@
     }
     catch (const sdbusplus::exception::SdBusError& e)
     {
-        log<level::ERR>("Error in mapper GetSubTreePath");
+        error("Error in mapper GetSubTreePath: {ERROR}", "ERROR", e);
         return;
     }
 
@@ -757,8 +755,7 @@
     auto pos = path.rfind("/");
     if (pos == std::string::npos)
     {
-        log<level::ERR>("No version id found in object path",
-                        entry("BIOS_OBJPATH=%s", path.c_str()));
+        error("No version id found in object path {PATH}", "PATH", path);
         return;
     }
 
diff --git a/msl_verify.cpp b/msl_verify.cpp
index 6a1c7aa..b74f6e9 100644
--- a/msl_verify.cpp
+++ b/msl_verify.cpp
@@ -4,11 +4,12 @@
 
 #include "version.hpp"
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
+#include <xyz/openbmc_project/Software/Version/server.hpp>
 
 #include <regex>
 
-using namespace phosphor::logging;
+PHOSPHOR_LOG2_USING;
 
 int minimum_ship_level::compare(const Version& versionToCompare,
                                 const Version& mslVersion)
@@ -44,8 +45,7 @@
 
     if (!std::regex_search(inpVersion, match, rx))
     {
-        log<level::ERR>("Unable to parse BMC version",
-                        entry("VERSION=%s", inpVersion.c_str()));
+        error("Unable to parse BMC version: {VERSION}", "VERSION", inpVersion);
         return;
     }
 
@@ -83,12 +83,12 @@
     auto rc = compare(actualVersion, mslVersion);
     if (rc < 0)
     {
-        log<level::ERR>(
-            "BMC Minimum Ship Level NOT met",
-            entry("MIN_VERSION=%s", msl.c_str()),
-            entry("ACTUAL_VERSION=%s", tmpStr.c_str()),
-            entry("VERSION_PURPOSE=%s",
-                  "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"));
+        auto purpose = sdbusplus::xyz::openbmc_project::Software::server::
+            Version::VersionPurpose::BMC;
+        error(
+            "BMC Minimum Ship Level ({MIN_VERSION}) NOT met by {ACTUAL_VERSION}",
+            "MIN_VERSION", msl, "ACTUAL_VERSION", tmpStr, "VERSION_PURPOSE",
+            purpose);
         return false;
     }
 
diff --git a/serialize.cpp b/serialize.cpp
index a6956c2..c471188 100644
--- a/serialize.cpp
+++ b/serialize.cpp
@@ -3,7 +3,7 @@
 #include "serialize.hpp"
 
 #include <cereal/archives/json.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/server.hpp>
 
 #include <filesystem>
@@ -16,7 +16,7 @@
 namespace updater
 {
 
-using namespace phosphor::logging;
+PHOSPHOR_LOG2_USING;
 namespace fs = std::filesystem;
 
 const std::string priorityName = "priority";
@@ -30,8 +30,7 @@
         if (fs::exists(path))
         {
             // Delete if it's a non-directory file
-            log<level::WARNING>("Removing non-directory file",
-                                entry("PATH=%s", path.c_str()));
+            warning("Removing non-directory file: {PATH}", "PATH", path);
             fs::remove_all(path);
         }
         fs::create_directories(path);
@@ -51,8 +50,7 @@
         if (fs::exists(path))
         {
             // Delete if it's a non-directory file
-            log<level::WARNING>("Removing non-directory file",
-                                entry("PATH=%s", path.c_str()));
+            warning("Removing non-directory file: {PATH}", "PATH", path);
             fs::remove_all(path);
         }
         fs::create_directories(path);
@@ -117,7 +115,9 @@
         }
     }
     catch (const std::exception& e)
-    {}
+    {
+        error("Error during processing: {ERROR}", "ERROR", e);
+    }
 
     return false;
 }
diff --git a/sync_manager.cpp b/sync_manager.cpp
index bdf8ac4..1a3e0dd 100644
--- a/sync_manager.cpp
+++ b/sync_manager.cpp
@@ -6,7 +6,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <filesystem>
 
@@ -17,7 +17,7 @@
 namespace manager
 {
 
-using namespace phosphor::logging;
+PHOSPHOR_LOG2_USING;
 namespace fs = std::filesystem;
 
 int Sync::processEntry(int mask, const fs::path& entryPath)
@@ -52,9 +52,8 @@
             execl("/usr/bin/rsync", "rsync", "-a", entryPath.c_str(),
                   dst.c_str(), nullptr);
             // execl only returns on fail
-            log<level::ERR>("Error occurred during the rsync call",
-                            entry("ERRNO=%d", errno),
-                            entry("PATH=%s", entryPath.c_str()));
+            error("Error ({ERRNO}) occurred during the rsync call on {PATH}",
+                  "ERRNO", errno, "PATH", entryPath);
             return -1;
         }
         else if (mask & IN_DELETE)
@@ -62,9 +61,9 @@
             execl("/usr/bin/rsync", "rsync", "-a", "--delete",
                   entryPath.c_str(), dst.c_str(), nullptr);
             // execl only returns on fail
-            log<level::ERR>("Error occurred during the rsync delete call",
-                            entry("ERRNO=%d", errno),
-                            entry("PATH=%s", entryPath.c_str()));
+            error(
+                "Error ({ERRNO}) occurred during the rsync delete call on {PATH}",
+                "ERRNO", errno, "PATH", entryPath);
             return -1;
         }
     }
@@ -74,7 +73,7 @@
     }
     else
     {
-        log<level::ERR>("Error occurred during fork", entry("ERRNO=%d", errno));
+        error("Error ({ERRNO}) occurred during fork", "ERRNO", errno);
         return -1;
     }
 
diff --git a/sync_manager_main.cpp b/sync_manager_main.cpp
index ee2ce83..271e67b 100644
--- a/sync_manager_main.cpp
+++ b/sync_manager_main.cpp
@@ -5,7 +5,7 @@
 
 #include <systemd/sd-event.h>
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/manager.hpp>
 
@@ -33,8 +33,7 @@
     }
     catch (std::exception& e)
     {
-        using namespace phosphor::logging;
-        log<level::ERR>(e.what());
+        lg2::error("Error in event loop: {ERROR}", "ERROR", e);
         sd_event_unref(loop);
         return -1;
     }
diff --git a/sync_watch.cpp b/sync_watch.cpp
index 7f1f970..e84d061 100644
--- a/sync_watch.cpp
+++ b/sync_watch.cpp
@@ -5,7 +5,7 @@
 #include <sys/inotify.h>
 #include <unistd.h>
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <filesystem>
 #include <fstream>
@@ -17,7 +17,7 @@
 namespace manager
 {
 
-using namespace phosphor::logging;
+PHOSPHOR_LOG2_USING;
 
 void SyncWatch::addInotifyWatch(const fs::path& path)
 {
@@ -25,8 +25,8 @@
         inotify_add_watch(inotifyFd, path.c_str(), IN_CLOSE_WRITE | IN_DELETE);
     if (-1 == wd)
     {
-        log<level::ERR>("inotify_add_watch failed", entry("ERRNO=%d", errno),
-                        entry("FILENAME=%s", path.c_str()));
+        error("inotify_add_watch on {PATH} failed: {ERRNO}", "ERRNO", errno,
+              "PATH", path);
         return;
     }
 
@@ -41,7 +41,7 @@
     auto fd = inotify_init1(IN_NONBLOCK);
     if (-1 == fd)
     {
-        log<level::ERR>("inotify_init1 failed", entry("ERRNO=%d", errno));
+        error("inotify_init1 failed: {ERRNO}", "ERRNO", errno);
         return;
     }
     inotifyFd = fd;
@@ -49,7 +49,7 @@
     auto rc = sd_event_add_io(&loop, nullptr, fd, EPOLLIN, callback, this);
     if (0 > rc)
     {
-        log<level::ERR>("failed to add to event loop", entry("RC=%d", rc));
+        error("failed to add to event loop: {RC}", "RC", rc);
         return;
     }
 
@@ -104,10 +104,8 @@
             }
             else
             {
-                log<level::INFO>(
-                    "The inotify watch was removed",
-                    entry("FILENAME=%s",
-                          (syncWatch->fileMap[event->wd]).c_str()));
+                info("The inotify watch on {PATH} was removed", "PATH",
+                     syncWatch->fileMap[event->wd]);
             }
             return 0;
         }
diff --git a/ubi/item_updater_helper.cpp b/ubi/item_updater_helper.cpp
index 873bf17..5cb10e0 100644
--- a/ubi/item_updater_helper.cpp
+++ b/ubi/item_updater_helper.cpp
@@ -4,7 +4,7 @@
 
 #include "utils.hpp"
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/exception.hpp>
 
 namespace phosphor
@@ -14,7 +14,7 @@
 namespace updater
 {
 
-using namespace phosphor::logging;
+PHOSPHOR_LOG2_USING;
 using sdbusplus::exception::SdBusError;
 
 void Helper::setEntry(const std::string& entryId, uint8_t value)
@@ -77,8 +77,7 @@
     }
     catch (const SdBusError& e)
     {
-        log<level::ERR>("Failed to update u-boot env variables",
-                        entry("VERSIONID=%s", versionId.c_str()));
+        error("Failed to update u-boot env variables", "VERSIONID", versionid);
     }
 }
 
@@ -95,7 +94,7 @@
     }
     catch (const SdBusError& e)
     {
-        log<level::ERR>("Failed to copy U-Boot to alternate chip");
+        error("Failed to copy U-Boot to alternate chip: {ERROR}", "ERROR", e);
     }
 }
 
diff --git a/utils.cpp b/utils.cpp
index f392983..e2c0f02 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -2,12 +2,12 @@
 
 #include <unistd.h>
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 namespace utils
 {
 
-using namespace phosphor::logging;
+PHOSPHOR_LOG2_USING;
 
 std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
                        const std::string& interface)
@@ -26,18 +26,16 @@
         reply.read(response);
         if (response.empty())
         {
-            log<level::ERR>("Error in mapper response for getting service name",
-                            entry("PATH=%s", path.c_str()),
-                            entry("INTERFACE=%s", interface.c_str()));
+            error(
+                "Empty response from mapper for getting service name: {PATH} {INTERFACE}",
+                "PATH", path, "INTERFACE", interface);
             return std::string{};
         }
     }
     catch (const sdbusplus::exception::SdBusError& e)
     {
-        log<level::ERR>("Error in mapper method call",
-                        entry("ERROR=%s", e.what()),
-                        entry("PATH=%s", path.c_str()),
-                        entry("INTERFACE=%s", interface.c_str()));
+        error("Error in mapper method call for ({PATH}, {INTERFACE}: {ERROR}",
+              "ERROR", e, "PATH", path, "INTERFACE", interface);
         return std::string{};
     }
     return response[0].first;
@@ -90,11 +88,11 @@
     {
         execv(path, args);
 
-        // execv only retruns on error
-        auto error = errno;
+        // execv only retruns on err
+        auto err = errno;
         auto command = buildCommandStr(path, args);
-        log<level::ERR>("Failed to execute command", entry("ERRNO=%d", error),
-                        entry("COMMAND=%s", command.c_str()));
+        error("Failed ({ERRNO}) to execute command: {COMMAND}", "ERRNO", err,
+              "COMMAND", command);
         return -1;
     }
     else if (pid > 0)
@@ -102,23 +100,20 @@
         int status;
         if (waitpid(pid, &status, 0) < 0)
         {
-            auto error = errno;
-            log<level::ERR>("waitpid error", entry("ERRNO=%d", error));
+            error("Error ({ERRNO}) during waitpid.", "ERRNO", errno);
             return -1;
         }
         else if (WEXITSTATUS(status) != 0)
         {
             auto command = buildCommandStr(path, args);
-            log<level::ERR>("Error occurred when executing command",
-                            entry("STATUS=%d", status),
-                            entry("COMMAND=%s", command.c_str()));
+            error("Error ({STATUS}) occurred when executing command: {COMMAND}",
+                  "STATUS", status, "COMMAND", command);
             return -1;
         }
     }
     else
     {
-        auto error = errno;
-        log<level::ERR>("Error occurred during fork", entry("ERRNO=%d", error));
+        error("Error ({ERRNO}) during fork.", "ERRNO", errno);
         return -1;
     }
 
diff --git a/version.cpp b/version.cpp
index f6bc363..97f3be9 100644
--- a/version.cpp
+++ b/version.cpp
@@ -7,7 +7,7 @@
 #include <openssl/sha.h>
 
 #include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <fstream>
 #include <iostream>
@@ -22,6 +22,7 @@
 namespace manager
 {
 
+PHOSPHOR_LOG2_USING;
 using namespace phosphor::logging;
 using Argument = xyz::openbmc_project::Common::InvalidArgument;
 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
@@ -34,7 +35,7 @@
 
     if (manifestFilePath.empty())
     {
-        log<level::ERR>("Error MANIFESTFilePath is empty");
+        error("ManifestFilePath is empty.");
         elog<InvalidArgument>(
             Argument::ARGUMENT_NAME("manifestFilePath"),
             Argument::ARGUMENT_VALUE(manifestFilePath.c_str()));
@@ -68,9 +69,8 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>("Error occurred when reading MANIFEST file",
-                        entry("KEY=%s", key.c_str()),
-                        entry("ERROR=%s", e.what()));
+        error("Error occurred when reading MANIFEST file: {ERROR}", "KEY", key,
+              "ERROR", e);
     }
 
     return value;
@@ -81,7 +81,7 @@
 
     if (version.empty())
     {
-        log<level::ERR>("Error version is empty");
+        error("Version is empty.");
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("Version"),
                               Argument::ARGUMENT_VALUE(version.c_str()));
     }
@@ -122,7 +122,7 @@
 
     if (machine.empty())
     {
-        log<level::ERR>("Unable to find OPENBMC_TARGET_MACHINE");
+        error("Unable to find OPENBMC_TARGET_MACHINE");
         elog<InternalFailure>();
     }
 
@@ -192,7 +192,7 @@
 
     if (version.empty())
     {
-        log<level::ERR>("Error BMC current version is empty");
+        error("BMC current version is empty");
         elog<InternalFailure>();
     }
 
diff --git a/watch.cpp b/watch.cpp
index 90f75a7..38887d4 100644
--- a/watch.cpp
+++ b/watch.cpp
@@ -7,7 +7,7 @@
 #include <sys/inotify.h>
 #include <unistd.h>
 
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <cstddef>
 #include <cstring>
@@ -22,7 +22,7 @@
 namespace manager
 {
 
-using namespace phosphor::logging;
+PHOSPHOR_LOG2_USING;
 using namespace std::string_literals;
 namespace fs = std::filesystem;
 
@@ -103,8 +103,8 @@
             auto rc = static_cast<Watch*>(userdata)->imageCallback(tarballPath);
             if (rc < 0)
             {
-                log<level::ERR>("Error processing image",
-                                entry("IMAGE=%s", tarballPath.c_str()));
+                error("Error ({RC}) processing image {IMAGE}", "RC", rc,
+                      "IMAGE", tarballPath);
             }
         }