logging: switch to lg2

After switching to C++20, it is recommended to use `phosphor::lg2`
to format log, and the correct `CODE_LINE` and `CODE_FUNC` values
can be used in log tracking.

Tested: built biosConfigManager successfully.
journalctl -o json-pretty SYSLOG_IDENTIFIER=biosconfig-manager
{
 "_TRANSPORT" : "journal",
 "_PID" : "244",
 "__MONOTONIC_TIMESTAMP" : "513878067",
 "_SYSTEMD_SLICE" : "system.slice",
 "CODE_LINE" : "123",
 "_SOURCE_REALTIME_TIMESTAMP" : "513877941",
 "_HOSTNAME" : "fp5280g2",
 "_CAP_EFFECTIVE" : "1ffffffffff",
 "_BOOT_ID" : "40382c3612f54e1a96a6ecf41fe6b38e",
 "SYSLOG_IDENTIFIER" : "biosconfig-manager",
 "_CMDLINE" : "/usr/bin/biosconfig-manager",
 "_EXE" : "/usr/bin/biosconfig-manager",
 "LOG2_FMTMSG" : "BIOS attribute not found in the BaseBIOSTable",
 "_SYSTEMD_UNIT" : "xyz.openbmc_project.biosconfig_manager.service",
 "MESSAGE" : "BIOS attribute not found in the BaseBIOSTable",
 "PRIORITY" : "3",
 "CODE_FILE" : "../biosconfig-manager/src/manager.cpp",
 "CODE_FUNC" : "virtual bios_config::Manager::PendingAttributes
                bios_config::Manager::pendingAttributes
               (bios_config::Manager::PendingAttributes)"
...
}

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I274d61827279b10ba3fe9d61404ce8b654ccdd9e
diff --git a/src/password.cpp b/src/password.cpp
index 3aacc45..5231120 100644
--- a/src/password.cpp
+++ b/src/password.cpp
@@ -21,6 +21,7 @@
 #include <boost/algorithm/hex.hpp>
 #include <boost/asio.hpp>
 #include <phosphor-logging/elog-errors.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/asio/connection.hpp>
 #include <sdbusplus/asio/object_server.hpp>
 
@@ -36,7 +37,7 @@
                        const std::array<uint8_t, maxSeedSize>& seed,
                        const std::string rawData, const std::string algo)
 {
-    phosphor::logging::log<phosphor::logging::level::ERR>("isMatch");
+    lg2::error("isMatch");
 
     if (algo == "SHA256")
     {
@@ -49,9 +50,8 @@
                 reinterpret_cast<const unsigned char*>(seed.data()),
                 seed.size(), iterValue, EVP_sha256(), hashLen, output.data()))
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Generate PKCS5_PBKDF2_HMAC_SHA256 Integrity Check Value "
-                "failed");
+            lg2::error(
+                "Generate PKCS5_PBKDF2_HMAC_SHA256 Integrity Check Value failed");
             throw InternalFailure();
         }
 
@@ -78,9 +78,8 @@
                 reinterpret_cast<const unsigned char*>(seed.data()),
                 seed.size(), iterValue, EVP_sha384(), hashLen, output.data()))
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(
-                "Generate PKCS5_PBKDF2_HMAC_SHA384 Integrity Check Value "
-                "failed");
+            lg2::error(
+                "Generate PKCS5_PBKDF2_HMAC_SHA384 Integrity Check Value failed");
             throw InternalFailure();
         }
 
@@ -121,8 +120,8 @@
                 }
                 catch (const nlohmann::json::parse_error& e)
                 {
-                    phosphor::logging::log<phosphor::logging::level::ERR>(
-                        e.what());
+                    lg2::error("Failed to parse JSON file: {ERROR}", "ERROR",
+                               e);
                     throw InternalFailure();
                 }
 
@@ -142,7 +141,7 @@
         }
         catch (nlohmann::detail::exception& e)
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
+            lg2::error("Failed to parse JSON file: {ERROR}", "ERROR", e);
             throw InternalFailure();
         }
         if (userName == "AdminPassword")
@@ -171,7 +170,7 @@
                     seed.size(), iterValue, EVP_sha256(), mdLen,
                     mNewPwdHash.data()))
             {
-                phosphor::logging::log<phosphor::logging::level::ERR>(
+                lg2::error(
                     "Verify PKCS5_PBKDF2_HMAC_SHA256 Integrity Check failed");
                 throw InternalFailure();
             }
@@ -188,7 +187,7 @@
                     seed.size(), iterValue, EVP_sha384(), mdLen,
                     mNewPwdHash.data()))
             {
-                phosphor::logging::log<phosphor::logging::level::ERR>(
+                lg2::error(
                     "Verify PKCS5_PBKDF2_HMAC_SHA384 Integrity Check failed");
                 throw InternalFailure();
             }
@@ -200,8 +199,7 @@
 void Password::changePassword(std::string userName, std::string currentPassword,
                               std::string newPassword)
 {
-    phosphor::logging::log<phosphor::logging::level::DEBUG>(
-        "BIOS config changePassword");
+    lg2::debug("BIOS config changePassword");
     verifyPassword(userName, currentPassword, newPassword);
 
     std::ifstream fs(seedFile.c_str());
@@ -215,7 +213,7 @@
         }
         catch (const nlohmann::json::parse_error& e)
         {
-            phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
+            lg2::error("Failed to parse JSON file: {ERROR}", "ERROR", e);
             throw InternalFailure();
         }
 
@@ -233,8 +231,7 @@
     }
     else
     {
-        phosphor::logging::log<phosphor::logging::level::DEBUG>(
-            "Cannot open file stream");
+        lg2::debug("Cannot open file stream");
         throw InternalFailure();
     }
 }
@@ -244,8 +241,7 @@
         *systemBus, objectPathPwd),
     objServer(objectServer), systemBus(systemBus)
 {
-    phosphor::logging::log<phosphor::logging::level::DEBUG>(
-        "BIOS config password is runing");
+    lg2::debug("BIOS config password is runing");
     try
     {
         fs::path biosDir(BIOS_PERSIST_PATH);
@@ -254,7 +250,7 @@
     }
     catch (const fs::filesystem_error& e)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
+        lg2::error("Failed to parse JSON file: {ERROR}", "ERROR", e);
         throw InternalFailure();
     }
 }