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()));
}
}