Switch to lg2 for logging

After enabling C++20, lg2 is preferred for logging. This patch replaces
all phosphor::logging::log calls to lg2 calls.

Tested:
Build pass.

Change-Id: Ic37bc36f43c2b3a1c61b1328af95e3a41c8d6d40
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/phosphor-ldap-config/ldap_config.cpp b/phosphor-ldap-config/ldap_config.cpp
index b7bd4c6..45968ac 100644
--- a/phosphor-ldap-config/ldap_config.cpp
+++ b/phosphor-ldap-config/ldap_config.cpp
@@ -152,7 +152,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
 }
@@ -170,7 +170,6 @@
             {
                 if (enabled())
                 {
-
                     writeConfig();
                 }
                 parent.startOrStopService(nslcdService, enabled());
@@ -181,7 +180,7 @@
             }
             catch (const std::exception& e)
             {
-                log<level::ERR>(e.what());
+                lg2::error("Exception: {ERR}", "ERR", e);
                 elog<InternalFailure>();
             }
         }
@@ -320,7 +319,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
     return;
@@ -347,7 +346,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
     return value;
@@ -372,16 +371,15 @@
         }
         else
         {
-            log<level::ERR>("bad LDAP Server URI",
-                            entry("LDAPSERVERURI=%s", value.c_str()));
+            lg2::error("Bad LDAP Server URI {URI}", "URI", value);
             elog<InvalidArgument>(Argument::ARGUMENT_NAME("ldapServerURI"),
                                   Argument::ARGUMENT_VALUE(value.c_str()));
         }
 
         if (secureLDAP && !fs::exists(tlsCacertFile.c_str()))
         {
-            log<level::ERR>("LDAP server's CA certificate not provided",
-                            entry("TLSCACERTFILE=%s", tlsCacertFile.c_str()));
+            lg2::error("LDAP server CA certificate not found at {PATH}", "PATH",
+                       tlsCacertFile);
             elog<NoCACertificate>();
         }
         val = ConfigIface::ldapServerURI(value);
@@ -407,7 +405,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
     return val;
@@ -425,8 +423,8 @@
 
         if (value.empty())
         {
-            log<level::ERR>("Not a valid LDAP BINDDN",
-                            entry("LDAPBINDDN=%s", value.c_str()));
+            lg2::error("'{BINDDN}' is not a valid LDAP BindDN", "BINDDN",
+                       value);
             elog<InvalidArgument>(Argument::ARGUMENT_NAME("ldapBindDN"),
                                   Argument::ARGUMENT_VALUE(value.c_str()));
         }
@@ -450,7 +448,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
     return val;
@@ -468,8 +466,8 @@
 
         if (value.empty())
         {
-            log<level::ERR>("Not a valid LDAP BASEDN",
-                            entry("BASEDN=%s", value.c_str()));
+            lg2::error("'{BASEDN}' is not a valid LDAP BaseDN", "BASEDN",
+                       value);
             elog<InvalidArgument>(Argument::ARGUMENT_NAME("ldapBaseDN"),
                                   Argument::ARGUMENT_VALUE(value.c_str()));
         }
@@ -493,7 +491,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
     return val;
@@ -525,7 +523,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
     return val;
@@ -569,7 +567,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
     return isEnable;
@@ -601,7 +599,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
     return val;
@@ -633,7 +631,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
     return val;
@@ -731,7 +729,7 @@
     }
     catch (const cereal::Exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Exception: {ERR}", "ERR", e);
         std::error_code ec;
         fs::remove(configPersistPath, ec);
         return false;
@@ -786,7 +784,7 @@
 {
     if (groupName.empty())
     {
-        log<level::ERR>("Group name is empty");
+        lg2::error("Group name is empty");
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("Group name"),
                               Argument::ARGUMENT_VALUE("Null"));
     }
@@ -795,7 +793,8 @@
     {
         if (val.second.get()->groupName() == groupName)
         {
-            log<level::ERR>("Group name already exists");
+            lg2::error("Group name '{GROUPNAME}' already exists", "GROUPNAME",
+                       groupName);
             elog<PrivilegeMappingExists>();
         }
     }
@@ -805,15 +804,15 @@
 {
     if (privilege.empty())
     {
-        log<level::ERR>("Privilege level is empty");
+        lg2::error("Privilege level is empty");
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("Privilege level"),
                               Argument::ARGUMENT_VALUE("Null"));
     }
 
     if (std::find(privMgr.begin(), privMgr.end(), privilege) == privMgr.end())
     {
-        log<level::ERR>("Invalid privilege");
-        elog<InvalidArgument>(Argument::ARGUMENT_NAME("Privilege level"),
+        lg2::error("Invalid privilege '{PRIVILEGE}'", "PRIVILEGE", privilege);
+        elog<InvalidArgument>(Argument::ARGUMENT_NAME("Privilege"),
                               Argument::ARGUMENT_VALUE(privilege.c_str()));
     }
 }
diff --git a/phosphor-ldap-config/ldap_config.hpp b/phosphor-ldap-config/ldap_config.hpp
index c1ba5ec..1528512 100644
--- a/phosphor-ldap-config/ldap_config.hpp
+++ b/phosphor-ldap-config/ldap_config.hpp
@@ -6,7 +6,7 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/object.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
diff --git a/phosphor-ldap-config/ldap_config_mgr.cpp b/phosphor-ldap-config/ldap_config_mgr.cpp
index a359273..d2ef4e0 100644
--- a/phosphor-ldap-config/ldap_config_mgr.cpp
+++ b/phosphor-ldap-config/ldap_config_mgr.cpp
@@ -17,7 +17,6 @@
 constexpr auto ldapScheme = "ldap";
 constexpr auto ldapsScheme = "ldaps";
 
-using namespace phosphor::logging;
 using namespace sdbusplus::xyz::openbmc_project::Common::Error;
 namespace fs = std::filesystem;
 using Argument = xyz::openbmc_project::Common::InvalidArgument;
@@ -52,9 +51,8 @@
     }
     catch (const sdbusplus::exception_t& ex)
     {
-        log<level::ERR>("Failed to restart service",
-                        entry("SERVICE=%s", service.c_str()),
-                        entry("ERR=%s", ex.what()));
+        lg2::error("Failed to restart service {SERVICE}: {ERR}", "SERVICE",
+                   service, "ERR", ex);
         elog<InternalFailure>();
     }
 }
@@ -69,9 +67,8 @@
     }
     catch (const sdbusplus::exception_t& ex)
     {
-        log<level::ERR>("Failed to stop service",
-                        entry("SERVICE=%s", service.c_str()),
-                        entry("ERR=%s", ex.what()));
+        lg2::error("Failed to stop service {SERVICE}: {ERR}", "SERVICE",
+                   service, "ERR", ex);
         elog<InternalFailure>();
     }
 }
@@ -94,31 +91,30 @@
     }
     else
     {
-        log<level::ERR>("bad LDAP Server URI",
-                        entry("LDAPSERVERURI=%s", ldapServerURI.c_str()));
+        lg2::error("Bad LDAP Server URI {URI}", "URI", ldapServerURI);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("ldapServerURI"),
                               Argument::ARGUMENT_VALUE(ldapServerURI.c_str()));
     }
 
     if (secureLDAP && !fs::exists(tlsCacertFile.c_str()))
     {
-        log<level::ERR>("LDAP server's CA certificate not provided",
-                        entry("TLSCACERTFILE=%s", tlsCacertFile.c_str()));
+        lg2::error("LDAP server CA certificate not found at {PATH}", "PATH",
+                   tlsCacertFile);
         elog<NoCACertificate>();
     }
 
     if (ldapBindDN.empty())
     {
-        log<level::ERR>("Not a valid LDAP BINDDN",
-                        entry("LDAPBINDDN=%s", ldapBindDN.c_str()));
+        lg2::error("'{BINDDN}' is not a valid LDAP BindDN", "BINDDN",
+                   ldapBindDN);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("LDAPBindDN"),
                               Argument::ARGUMENT_VALUE(ldapBindDN.c_str()));
     }
 
     if (ldapBaseDN.empty())
     {
-        log<level::ERR>("Not a valid LDAP BASEDN",
-                        entry("LDAPBASEDN=%s", ldapBaseDN.c_str()));
+        lg2::error("'{BASEDN}' is not a valid LDAP BaseDN", "BASEDN",
+                   ldapBaseDN);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("LDAPBaseDN"),
                               Argument::ARGUMENT_VALUE(ldapBaseDN.c_str()));
     }
diff --git a/phosphor-ldap-config/ldap_config_mgr.hpp b/phosphor-ldap-config/ldap_config_mgr.hpp
index 850fc54..3b48127 100644
--- a/phosphor-ldap-config/ldap_config_mgr.hpp
+++ b/phosphor-ldap-config/ldap_config_mgr.hpp
@@ -6,7 +6,7 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 #include <xyz/openbmc_project/User/Ldap/Config/server.hpp>
diff --git a/phosphor-ldap-config/ldap_mapper_entry.cpp b/phosphor-ldap-config/ldap_mapper_entry.cpp
index af57e2d..f903c1f 100644
--- a/phosphor-ldap-config/ldap_mapper_entry.cpp
+++ b/phosphor-ldap-config/ldap_mapper_entry.cpp
@@ -7,7 +7,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/User/Common/error.hpp>
 
diff --git a/phosphor-ldap-config/ldap_mapper_serialize.cpp b/phosphor-ldap-config/ldap_mapper_serialize.cpp
index 66cea37..2842ba2 100644
--- a/phosphor-ldap-config/ldap_mapper_serialize.cpp
+++ b/phosphor-ldap-config/ldap_mapper_serialize.cpp
@@ -4,7 +4,7 @@
 
 #include <cereal/archives/binary.hpp>
 #include <cereal/types/string.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 
 #include <fstream>
 
@@ -18,8 +18,6 @@
 namespace ldap
 {
 
-using namespace phosphor::logging;
-
 /** @brief Function required by Cereal to perform serialization.
  *
  *  @tparam Archive - Cereal archive type (binary in this case).
@@ -82,13 +80,15 @@
     }
     catch (const cereal::Exception& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Failed to deserialize {FILE}: {ERR}", "FILE", path, "ERR",
+                   e);
         fs::remove(path);
         return false;
     }
     catch (const std::length_error& e)
     {
-        log<level::ERR>(e.what());
+        lg2::error("Failed to deserialize {FILE}: {ERR}", "FILE", path, "ERR",
+                   e);
         fs::remove(path);
         return false;
     }
diff --git a/phosphor-ldap-config/main.cpp b/phosphor-ldap-config/main.cpp
index e2bedaf..be97abd 100644
--- a/phosphor-ldap-config/main.cpp
+++ b/phosphor-ldap-config/main.cpp
@@ -3,7 +3,7 @@
 #include "ldap_config_mgr.hpp"
 
 #include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
@@ -21,8 +21,8 @@
                                  phosphor::ldap::defaultNslcdFile) ||
         !std::filesystem::exists(configDir / phosphor::ldap::nsSwitchFile))
     {
-        log<level::ERR>("Error starting LDAP Config App, configfile(s) are "
-                        "missing, exiting!!!");
+        lg2::error("Failed to start phosphor-ldap-manager, configfile(s) are "
+                   "missing");
         elog<InternalFailure>();
     }
     auto bus = sdbusplus::bus::new_default();
diff --git a/shadowlock.hpp b/shadowlock.hpp
index f274966..854874d 100644
--- a/shadowlock.hpp
+++ b/shadowlock.hpp
@@ -5,7 +5,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>
@@ -36,7 +36,7 @@
     {
         if (!lckpwdf())
         {
-            log<level::ERR>("Locking Shadow failed");
+            lg2::error("Failed to lock shadow file");
             elog<InternalFailure>();
         }
     }
@@ -44,7 +44,7 @@
     {
         if (!ulckpwdf())
         {
-            log<level::ERR>("Un-Locking Shadow failed");
+            lg2::error("Failed to unlock shadow file");
             elog<InternalFailure>();
         }
     }
diff --git a/test/ldap_config_test.cpp b/test/ldap_config_test.cpp
index c210b84..6e4e6d2 100644
--- a/test/ldap_config_test.cpp
+++ b/test/ldap_config_test.cpp
@@ -6,7 +6,7 @@
 #include <sys/types.h>
 
 #include <phosphor-logging/elog-errors.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 #include <xyz/openbmc_project/User/Common/error.hpp>
diff --git a/user_mgr.cpp b/user_mgr.cpp
index e085b28..a2b6a76 100644
--- a/user_mgr.cpp
+++ b/user_mgr.cpp
@@ -33,7 +33,7 @@
 #include <boost/algorithm/string/split.hpp>
 #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/User/Common/error.hpp>
 
@@ -138,8 +138,8 @@
     }
     if (!allowed)
     {
-        log<level::ERR>("Invalid group name; not in the allowed list",
-                        entry("GroupName=%s", groupName.c_str()));
+        lg2::error("Group name '{GROUP}' is not in the allowed list", "GROUP",
+                   groupName);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("Group Name"),
                               Argument::ARGUMENT_VALUE(groupName.c_str()));
     }
@@ -184,7 +184,7 @@
 {
     if (userName.empty())
     {
-        log<level::ERR>("User name is empty");
+        lg2::error("User name is empty");
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("User name"),
                               Argument::ARGUMENT_VALUE("Null"));
     }
@@ -199,8 +199,7 @@
 {
     if (!isUserExist(userName))
     {
-        log<level::ERR>("User does not exist",
-                        entry("USER_NAME=%s", userName.c_str()));
+        lg2::error("User '{USERNAME}' does not exist", "USERNAME", userName);
         elog<UserNameDoesNotExist>();
     }
 }
@@ -212,8 +211,7 @@
         !std::regex_match(groupName.c_str(),
                           std::regex("[a-zA-z_][a-zA-Z_0-9]*")))
     {
-        log<level::ERR>("Invalid group name",
-                        entry("GroupName=%s", groupName.c_str()));
+        lg2::error("Invalid group name '{GROUP}'", "GROUP", groupName);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("Group Name"),
                               Argument::ARGUMENT_VALUE(groupName.c_str()));
     }
@@ -224,8 +222,7 @@
 {
     if (isUserExist(userName))
     {
-        log<level::ERR>("User already exists",
-                        entry("USER_NAME=%s", userName.c_str()));
+        lg2::error("User '{USERNAME}' already exists", "USERNAME", userName);
         elog<UserNameExists>();
     }
 }
@@ -238,8 +235,10 @@
     {
         if (userName.length() > ipmiMaxUserNameLen)
         {
-            log<level::ERR>("IPMI user name length limitation",
-                            entry("SIZE=%d", userName.length()));
+            lg2::error("User '{USERNAME}' exceeds IPMI username length limit "
+                       "({LENGTH} > {LIMIT})",
+                       "USERNAME", userName, "LENGTH", userName.length(),
+                       "LIMIT", ipmiMaxUserNameLen);
             elog<UserNameGroupFail>(
                 xyz::openbmc_project::User::Common::UserNameGroupFail::REASON(
                     "IPMI length"));
@@ -247,16 +246,17 @@
     }
     if (userName.length() > systemMaxUserNameLen)
     {
-        log<level::ERR>("User name length limitation",
-                        entry("SIZE=%d", userName.length()));
+        lg2::error("User '{USERNAME}' exceeds system username length limit "
+                   "({LENGTH} > {LIMIT})",
+                   "USERNAME", userName, "LENGTH", userName.length(), "LIMIT",
+                   systemMaxUserNameLen);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("User name"),
                               Argument::ARGUMENT_VALUE("Invalid length"));
     }
     if (!std::regex_match(userName.c_str(),
                           std::regex("[a-zA-z_][a-zA-Z_0-9]*")))
     {
-        log<level::ERR>("Invalid user name",
-                        entry("USER_NAME=%s", userName.c_str()));
+        lg2::error("Invalid username '{USERNAME}'", "USERNAME", userName);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("User name"),
                               Argument::ARGUMENT_VALUE("Invalid data"));
     }
@@ -270,10 +270,10 @@
     {
         if (getIpmiUsersCount() >= ipmiMaxUsers)
         {
-            log<level::ERR>("IPMI user limit reached");
+            lg2::error("IPMI user limit reached");
             elog<NoResource>(
                 xyz::openbmc_project::User::Common::NoResource::REASON(
-                    "ipmi user count reached"));
+                    "IPMI user limit reached"));
         }
     }
     else
@@ -281,10 +281,10 @@
         if (usersList.size() > 0 && (usersList.size() - getIpmiUsersCount()) >=
                                         (maxSystemUsers - ipmiMaxUsers))
         {
-            log<level::ERR>("Non-ipmi User limit reached");
+            lg2::error("Non-ipmi User limit reached");
             elog<NoResource>(
                 xyz::openbmc_project::User::Common::NoResource::REASON(
-                    "Non-ipmi user count reached"));
+                    "Non-ipmi user limit reached"));
         }
     }
     return;
@@ -295,7 +295,7 @@
     if (!priv.empty() &&
         (std::find(privMgr.begin(), privMgr.end(), priv) == privMgr.end()))
     {
-        log<level::ERR>("Invalid privilege");
+        lg2::error("Invalid privilege '{PRIVILEGE}'", "PRIVILEGE", priv);
         elog<InvalidArgument>(Argument::ARGUMENT_NAME("Privilege"),
                               Argument::ARGUMENT_VALUE(priv.c_str()));
     }
@@ -308,7 +308,7 @@
         if (std::find(groupsMgr.begin(), groupsMgr.end(), group) ==
             groupsMgr.end())
         {
-            log<level::ERR>("Invalid Group Name listed");
+            lg2::error("Invalid Group Name '{GROUPNAME}'", "GROUPNAME", group);
             elog<InvalidArgument>(Argument::ARGUMENT_NAME("GroupName"),
                                   Argument::ARGUMENT_VALUE(group.c_str()));
         }
@@ -370,7 +370,8 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("Unable to create new user");
+        lg2::error("Unable to create new user '{USERNAME}'", "USERNAME",
+                   userName);
         elog<InternalFailure>();
     }
 
@@ -383,8 +384,7 @@
         userName, std::make_unique<phosphor::user::Users>(
                       bus, userObj.c_str(), groupNames, priv, enabled, *this));
 
-    log<level::INFO>("User created successfully",
-                     entry("USER_NAME=%s", userName.c_str()));
+    lg2::info("User '{USERNAME}' created successfully", "USERNAME", userName);
     return;
 }
 
@@ -399,15 +399,13 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("User delete failed",
-                        entry("USER_NAME=%s", userName.c_str()));
+        lg2::error("Delete User '{USERNAME}' failed", "USERNAME", userName);
         elog<InternalFailure>();
     }
 
     usersList.erase(userName);
 
-    log<level::INFO>("User deleted successfully",
-                     entry("USER_NAME=%s", userName.c_str()));
+    lg2::info("User '{USERNAME}' deleted successfully", "USERNAME", userName);
     return;
 }
 
@@ -416,8 +414,7 @@
     if (std::find(groupsMgr.begin(), groupsMgr.end(), groupName) ==
         groupsMgr.end())
     {
-        log<level::ERR>("Group already exists",
-                        entry("GROUP_NAME=%s", groupName.c_str()));
+        lg2::error("Group '{GROUP}' already exists", "GROUP", groupName);
         elog<GroupNameDoesNotExists>();
     }
     checkAndThrowsForGroupChangeAllowed(groupName);
@@ -432,15 +429,13 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("Group delete failed",
-                        entry("GROUP_NAME=%s", groupName.c_str()));
+        lg2::error("Failed to delete group '{GROUP}'", "GROUP", groupName);
         elog<InternalFailure>();
     }
 
     groupsMgr.erase(std::find(groupsMgr.begin(), groupsMgr.end(), groupName));
     UserMgrIface::allGroups(groupsMgr);
-    log<level::INFO>("Group deleted successfully",
-                     entry("GROUP_NAME=%s", groupName.c_str()));
+    lg2::info("Successfully deleted group '{GROUP}'", "GROUP", groupName);
 }
 
 void UserMgr::checkCreateGroupConstraints(const std::string& groupName)
@@ -448,14 +443,13 @@
     if (std::find(groupsMgr.begin(), groupsMgr.end(), groupName) !=
         groupsMgr.end())
     {
-        log<level::ERR>("Group already exists",
-                        entry("GROUP_NAME=%s", groupName.c_str()));
+        lg2::error("Group '{GROUP}' already exists", "GROUP", groupName);
         elog<GroupNameExists>();
     }
     checkAndThrowForDisallowedGroupCreation(groupName);
     if (groupsMgr.size() >= maxSystemGroupCount)
     {
-        log<level::ERR>("Group limit reached");
+        lg2::error("Group limit reached");
         elog<NoResource>(xyz::openbmc_project::User::Common::NoResource::REASON(
             "Group limit reached"));
     }
@@ -470,8 +464,7 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("Group create failed",
-                        entry("GROUP_NAME=%s", groupName.c_str()));
+        lg2::error("Failed to create group '{GROUP}'", "GROUP", groupName);
         elog<InternalFailure>();
     }
     groupsMgr.push_back(groupName);
@@ -492,8 +485,8 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("User rename failed",
-                        entry("USER_NAME=%s", userName.c_str()));
+        lg2::error("Rename '{USERNAME}' to '{NEWUSERNAME}' failed", "USERNAME",
+                   userName, "NEWUSERNAME", newUserName);
         elog<InternalFailure>();
     }
     const auto& user = usersList[userName];
@@ -556,16 +549,17 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("Unable to modify user privilege / groups");
+        lg2::error(
+            "Unable to modify user privilege / groups for user '{USERNAME}'",
+            "USERNAME", userName);
         elog<InternalFailure>();
     }
 
-    log<level::INFO>("User groups / privilege updated successfully",
-                     entry("USER_NAME=%s", userName.c_str()));
     std::sort(groupNames.begin(), groupNames.end());
     usersList[userName]->setUserGroups(groupNames);
     usersList[userName]->setUserPrivilege(priv);
-    return;
+    lg2::info("User '{USERNAME}' groups / privilege updated successfully",
+              "USERNAME", userName);
 }
 
 uint8_t UserMgr::minPasswordLength(uint8_t value)
@@ -576,10 +570,9 @@
     }
     if (value < minPasswdLength)
     {
-        log<level::ERR>(("Attempting to set minPasswordLength to less than " +
-                         std::to_string(minPasswdLength))
-                            .c_str(),
-                        entry("SIZE=%d", value));
+        lg2::error("Attempting to set minPasswordLength to {VALUE}, less than "
+                   "{MINVALUE}",
+                   "VALUE", value, "MINVALUE", minPasswdLength);
         elog<InvalidArgument>(
             Argument::ARGUMENT_NAME("minPasswordLength"),
             Argument::ARGUMENT_VALUE(std::to_string(value).c_str()));
@@ -587,7 +580,8 @@
     if (setPamModuleArgValue(pamCrackLib, minPasswdLenProp,
                              std::to_string(value)) != success)
     {
-        log<level::ERR>("Unable to set minPasswordLength");
+        lg2::error("Unable to set minPasswordLength to {VALUE}", "VALUE",
+                   value);
         elog<InternalFailure>();
     }
     return AccountPolicyIface::minPasswordLength(value);
@@ -602,7 +596,8 @@
     if (setPamModuleArgValue(pamPWHistory, remOldPasswdCount,
                              std::to_string(value)) != success)
     {
-        log<level::ERR>("Unable to set rememberOldPasswordTimes");
+        lg2::error("Unable to set rememberOldPasswordTimes to {VALUE}", "VALUE",
+                   value);
         elog<InternalFailure>();
     }
     return AccountPolicyIface::rememberOldPasswordTimes(value);
@@ -617,7 +612,8 @@
     if (setPamModuleArgValue(pamTally2, maxFailedAttempt,
                              std::to_string(value)) != success)
     {
-        log<level::ERR>("Unable to set maxLoginAttemptBeforeLockout");
+        lg2::error("Unable to set maxLoginAttemptBeforeLockout to {VALUE}",
+                   "VALUE", value);
         elog<InternalFailure>();
     }
     return AccountPolicyIface::maxLoginAttemptBeforeLockout(value);
@@ -632,7 +628,8 @@
     if (setPamModuleArgValue(pamTally2, unlockTimeout, std::to_string(value)) !=
         success)
     {
-        log<level::ERR>("Unable to set accountUnlockTimeout");
+        lg2::error("Unable to set accountUnlockTimeout to {VALUE}", "VALUE",
+                   value);
         elog<InternalFailure>();
     }
     return AccountPolicyIface::accountUnlockTimeout(value);
@@ -654,8 +651,8 @@
     std::ifstream fileToRead(fileName, std::ios::in);
     if (!fileToRead.is_open())
     {
-        log<level::ERR>("Failed to open pam configuration file",
-                        entry("FILE_NAME=%s", fileName.c_str()));
+        lg2::error("Failed to open pam configuration file {FILENAME}",
+                   "FILENAME", fileName);
         return failure;
     }
     std::string line;
@@ -709,8 +706,8 @@
     std::ofstream fileToWrite(tmpFileName, std::ios::out);
     if (!fileToRead.is_open() || !fileToWrite.is_open())
     {
-        log<level::ERR>("Failed to open pam configuration /tmp file",
-                        entry("FILE_NAME=%s", fileName.c_str()));
+        lg2::error("Failed to open pam configuration file {FILENAME}",
+                   "FILENAME", fileName);
         return failure;
     }
     std::string line;
@@ -772,15 +769,14 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("Unable to modify user enabled state");
+        lg2::error("Unable to modify user enabled state for '{USERNAME}'",
+                   "USERNAME", userName);
         elog<InternalFailure>();
     }
 
-    log<level::INFO>("User enabled/disabled state updated successfully",
-                     entry("USER_NAME=%s", userName.c_str()),
-                     entry("ENABLED=%d", enabled));
     usersList[userName]->setUserEnabled(enabled);
-    return;
+    lg2::info("User '{USERNAME}' has been {STATUS}", "USERNAME", userName,
+              "STATUS", enabled ? "Enabled" : "Disabled");
 }
 
 /**
@@ -811,7 +807,7 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("Unable to read login failure counter");
+        lg2::error("Unable to read login failure counter");
         elog<InternalFailure>();
     }
 
@@ -831,8 +827,7 @@
     }
     catch (const std::exception& e)
     {
-        log<level::ERR>("Exception for userLockedForFailedAttempt",
-                        entry("WHAT=%s", e.what()));
+        lg2::error("Exception for userLockedForFailedAttempt: {ERR}", "ERR", e);
         elog<InternalFailure>();
     }
 
@@ -845,7 +840,7 @@
     // available
     if (splitWords.size() < 4)
     {
-        log<level::ERR>("Unable to read latest failure date/time");
+        lg2::error("Unable to read latest failure date/time");
         elog<InternalFailure>();
     }
 
@@ -858,7 +853,7 @@
     std::tm tmStruct = {};
     if (!strptime(failDateTime.c_str(), "%D %H:%M:%S", &tmStruct))
     {
-        log<level::ERR>("Failed to parse latest failure date/time");
+        lg2::error("Failed to parse latest failure date/time");
         elog<InternalFailure>();
     }
 
@@ -889,7 +884,7 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("Unable to reset login failure counter");
+        lg2::error("Unable to reset login failure counter");
         elog<InternalFailure>();
     }
 
@@ -954,7 +949,7 @@
     phosphor::user::File passwd(passwdFileName, "r");
     if ((passwd)() == NULL)
     {
-        log<level::ERR>("Error opening the passwd file");
+        lg2::error("Error opening {FILENAME}", "FILENAME", passwdFileName);
         elog<InternalFailure>();
     }
 
@@ -1045,8 +1040,7 @@
     }
     else
     {
-        log<level::ERR>("Group not found",
-                        entry("GROUP=%s", groupName.c_str()));
+        lg2::error("Group '{GROUPNAME}' not found", "GROUPNAME", groupName);
         // Don't throw error, just return empty userList - fallback
     }
     return usersInGroup;
@@ -1071,15 +1065,13 @@
     }
     catch (const InternalFailure& e)
     {
-        log<level::ERR>("Unable to get the User Service",
-                        entry("WHAT=%s", e.what()));
+        lg2::error("Unable to get the User Service: {ERR}", "ERR", e);
         throw;
     }
     catch (const sdbusplus::exception_t& e)
     {
-        log<level::ERR>(
-            "Failed to excute method", entry("METHOD=%s", "GetManagedObjects"),
-            entry("PATH=%s", ldapMgrObjBasePath), entry("WHAT=%s", e.what()));
+        lg2::error("Failed to excute GetManagedObjects at {PATH}: {ERR}",
+                   "PATH", ldapMgrObjBasePath, "ERR", e);
         throw;
     }
     return objects;
@@ -1097,7 +1089,7 @@
 
     if (mapperResponseMsg.is_method_error())
     {
-        log<level::ERR>("Error in mapper call");
+        lg2::error("Error in mapper call");
         elog<InternalFailure>();
     }
 
@@ -1106,7 +1098,7 @@
 
     if (mapperResponse.begin() == mapperResponse.end())
     {
-        log<level::ERR>("Invalid response from mapper");
+        lg2::error("Invalid response from mapper");
         elog<InternalFailure>();
     }
 
@@ -1136,8 +1128,7 @@
         return pwd.pw_gid;
     }
 
-    log<level::ERR>("User noes not exist",
-                    entry("USER_NAME=%s", userName.c_str()));
+    lg2::error("User {USERNAME} does not exist", "USERNAME", userName);
     elog<UserNameDoesNotExist>();
 }
 
@@ -1167,8 +1158,8 @@
         buflen *= 2;
         buffer.resize(buflen);
 
-        log<level::DEBUG>("Increase buffer for getgrnam_r()",
-                          entry("BUFFER_LENGTH=%zu", buflen));
+        lg2::debug("Increase buffer for getgrnam_r() to {SIZE}", "SIZE",
+                   buflen);
 
         status = getgrnam_r(groupName.c_str(), &grp, buffer.data(),
                             buffer.size(), &grpPtr);
@@ -1194,13 +1185,12 @@
     }
     else if (status == ERANGE)
     {
-        log<level::ERR>("Group info requires too much memory",
-                        entry("GROUP_NAME=%s", groupName.c_str()));
+        lg2::error("Group info of {GROUP} requires too much memory", "GROUP",
+                   groupName);
     }
     else
     {
-        log<level::ERR>("Group does not exist",
-                        entry("GROUP_NAME=%s", groupName.c_str()));
+        lg2::error("Group {GROUP} does not exist", "GROUP", groupName);
     }
 
     return false;
@@ -1308,15 +1298,14 @@
             }
             else
             {
-                log<level::WARNING>("LDAP group privilege mapping does not "
-                                    "exist, default \"priv-user\" is used");
+                lg2::warning("LDAP group privilege mapping does not exist, "
+                             "default \"priv-user\" is used");
                 userInfo.emplace("UserPrivilege", "priv-user");
             }
         }
         catch (const std::bad_variant_access& e)
         {
-            log<level::ERR>("Error while accessing variant",
-                            entry("WHAT=%s", e.what()));
+            lg2::error("Error while accessing variant: {ERR}", "ERR", e);
             elog<InternalFailure>();
         }
         userInfo.emplace("RemoteUser", true);
@@ -1348,8 +1337,7 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>("Exception for MinPasswordLength",
-                            entry("WHAT=%s", e.what()));
+            lg2::error("Exception for MinPasswordLength: {ERR}", "ERR", e);
             throw;
         }
         AccountPolicyIface::minPasswordLength(value);
@@ -1374,8 +1362,8 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>("Exception for RememberOldPasswordTimes",
-                            entry("WHAT=%s", e.what()));
+            lg2::error("Exception for RememberOldPasswordTimes: {ERR}", "ERR",
+                       e);
             throw;
         }
         AccountPolicyIface::rememberOldPasswordTimes(value);
@@ -1399,8 +1387,8 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>("Exception for MaxLoginAttemptBeforLockout",
-                            entry("WHAT=%s", e.what()));
+            lg2::error("Exception for MaxLoginAttemptBeforLockout: {ERR}",
+                       "ERR", e);
             throw;
         }
         AccountPolicyIface::maxLoginAttemptBeforeLockout(value16);
@@ -1424,8 +1412,7 @@
         }
         catch (const std::exception& e)
         {
-            log<level::ERR>("Exception for AccountUnlockTimeout",
-                            entry("WHAT=%s", e.what()));
+            lg2::error("Exception for AccountUnlockTimeout: {ERR}", "ERR", e);
             throw;
         }
         AccountPolicyIface::accountUnlockTimeout(value32);
diff --git a/user_mgr.hpp b/user_mgr.hpp
index ec205e4..6dcc898 100644
--- a/user_mgr.hpp
+++ b/user_mgr.hpp
@@ -20,7 +20,7 @@
 #include <boost/process/io.hpp>
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/elog.hpp>
-#include <phosphor-logging/log.hpp>
+#include <phosphor-logging/lg2.hpp>
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/server/object.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
@@ -97,10 +97,8 @@
     int retCode = execProg.exit_code();
     if (retCode)
     {
-        phosphor::logging::log<phosphor::logging::level::ERR>(
-            "Command execution failed",
-            phosphor::logging::entry("PATH=%s", path),
-            phosphor::logging::entry("RETURN_CODE=%d", retCode));
+        lg2::error("Command {PATH} execution failed, return code {RETCODE}",
+                   "PATH", path, "RETCODE", retCode);
         phosphor::logging::elog<
             sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure>();
     }
diff --git a/users.cpp b/users.cpp
index 4340756..8d6df6a 100644
--- a/users.cpp
+++ b/users.cpp
@@ -26,7 +26,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/User/Common/error.hpp>