Skip to content

Commit 11ec666

Browse files
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 <[email protected]>
1 parent 5686206 commit 11ec666

12 files changed

+141
-161
lines changed

phosphor-ldap-config/ldap_config.cpp

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void Config::certificateInstalled(sdbusplus::message_t& /*msg*/)
152152
}
153153
catch (const std::exception& e)
154154
{
155-
log<level::ERR>(e.what());
155+
lg2::error("Exception: {ERR}", "ERR", e);
156156
elog<InternalFailure>();
157157
}
158158
}
@@ -170,7 +170,6 @@ void Config::certificateChanged(sdbusplus::message_t& msg)
170170
{
171171
if (enabled())
172172
{
173-
174173
writeConfig();
175174
}
176175
parent.startOrStopService(nslcdService, enabled());
@@ -181,7 +180,7 @@ void Config::certificateChanged(sdbusplus::message_t& msg)
181180
}
182181
catch (const std::exception& e)
183182
{
184-
log<level::ERR>(e.what());
183+
lg2::error("Exception: {ERR}", "ERR", e);
185184
elog<InternalFailure>();
186185
}
187186
}
@@ -320,7 +319,7 @@ void Config::writeConfig()
320319
}
321320
catch (const std::exception& e)
322321
{
323-
log<level::ERR>(e.what());
322+
lg2::error("Exception: {ERR}", "ERR", e);
324323
elog<InternalFailure>();
325324
}
326325
return;
@@ -347,7 +346,7 @@ std::string Config::ldapBindDNPassword(std::string value)
347346
}
348347
catch (const std::exception& e)
349348
{
350-
log<level::ERR>(e.what());
349+
lg2::error("Exception: {ERR}", "ERR", e);
351350
elog<InternalFailure>();
352351
}
353352
return value;
@@ -372,16 +371,15 @@ std::string Config::ldapServerURI(std::string value)
372371
}
373372
else
374373
{
375-
log<level::ERR>("bad LDAP Server URI",
376-
entry("LDAPSERVERURI=%s", value.c_str()));
374+
lg2::error("Bad LDAP Server URI {URI}", "URI", value);
377375
elog<InvalidArgument>(Argument::ARGUMENT_NAME("ldapServerURI"),
378376
Argument::ARGUMENT_VALUE(value.c_str()));
379377
}
380378

381379
if (secureLDAP && !fs::exists(tlsCacertFile.c_str()))
382380
{
383-
log<level::ERR>("LDAP server's CA certificate not provided",
384-
entry("TLSCACERTFILE=%s", tlsCacertFile.c_str()));
381+
lg2::error("LDAP server CA certificate not found at {PATH}", "PATH",
382+
tlsCacertFile);
385383
elog<NoCACertificate>();
386384
}
387385
val = ConfigIface::ldapServerURI(value);
@@ -407,7 +405,7 @@ std::string Config::ldapServerURI(std::string value)
407405
}
408406
catch (const std::exception& e)
409407
{
410-
log<level::ERR>(e.what());
408+
lg2::error("Exception: {ERR}", "ERR", e);
411409
elog<InternalFailure>();
412410
}
413411
return val;
@@ -425,8 +423,8 @@ std::string Config::ldapBindDN(std::string value)
425423

426424
if (value.empty())
427425
{
428-
log<level::ERR>("Not a valid LDAP BINDDN",
429-
entry("LDAPBINDDN=%s", value.c_str()));
426+
lg2::error("'{BINDDN}' is not a valid LDAP BindDN", "BINDDN",
427+
value);
430428
elog<InvalidArgument>(Argument::ARGUMENT_NAME("ldapBindDN"),
431429
Argument::ARGUMENT_VALUE(value.c_str()));
432430
}
@@ -450,7 +448,7 @@ std::string Config::ldapBindDN(std::string value)
450448
}
451449
catch (const std::exception& e)
452450
{
453-
log<level::ERR>(e.what());
451+
lg2::error("Exception: {ERR}", "ERR", e);
454452
elog<InternalFailure>();
455453
}
456454
return val;
@@ -468,8 +466,8 @@ std::string Config::ldapBaseDN(std::string value)
468466

469467
if (value.empty())
470468
{
471-
log<level::ERR>("Not a valid LDAP BASEDN",
472-
entry("BASEDN=%s", value.c_str()));
469+
lg2::error("'{BASEDN}' is not a valid LDAP BaseDN", "BASEDN",
470+
value);
473471
elog<InvalidArgument>(Argument::ARGUMENT_NAME("ldapBaseDN"),
474472
Argument::ARGUMENT_VALUE(value.c_str()));
475473
}
@@ -493,7 +491,7 @@ std::string Config::ldapBaseDN(std::string value)
493491
}
494492
catch (const std::exception& e)
495493
{
496-
log<level::ERR>(e.what());
494+
lg2::error("Exception: {ERR}", "ERR", e);
497495
elog<InternalFailure>();
498496
}
499497
return val;
@@ -525,7 +523,7 @@ ConfigIface::SearchScope Config::ldapSearchScope(ConfigIface::SearchScope value)
525523
}
526524
catch (const std::exception& e)
527525
{
528-
log<level::ERR>(e.what());
526+
lg2::error("Exception: {ERR}", "ERR", e);
529527
elog<InternalFailure>();
530528
}
531529
return val;
@@ -569,7 +567,7 @@ bool Config::enableService(bool value)
569567
}
570568
catch (const std::exception& e)
571569
{
572-
log<level::ERR>(e.what());
570+
lg2::error("Exception: {ERR}", "ERR", e);
573571
elog<InternalFailure>();
574572
}
575573
return isEnable;
@@ -601,7 +599,7 @@ std::string Config::userNameAttribute(std::string value)
601599
}
602600
catch (const std::exception& e)
603601
{
604-
log<level::ERR>(e.what());
602+
lg2::error("Exception: {ERR}", "ERR", e);
605603
elog<InternalFailure>();
606604
}
607605
return val;
@@ -633,7 +631,7 @@ std::string Config::groupNameAttribute(std::string value)
633631
}
634632
catch (const std::exception& e)
635633
{
636-
log<level::ERR>(e.what());
634+
lg2::error("Exception: {ERR}", "ERR", e);
637635
elog<InternalFailure>();
638636
}
639637
return val;
@@ -731,7 +729,7 @@ bool Config::deserialize()
731729
}
732730
catch (const cereal::Exception& e)
733731
{
734-
log<level::ERR>(e.what());
732+
lg2::error("Exception: {ERR}", "ERR", e);
735733
std::error_code ec;
736734
fs::remove(configPersistPath, ec);
737735
return false;
@@ -786,7 +784,7 @@ void Config::checkPrivilegeMapper(const std::string& groupName)
786784
{
787785
if (groupName.empty())
788786
{
789-
log<level::ERR>("Group name is empty");
787+
lg2::error("Group name is empty");
790788
elog<InvalidArgument>(Argument::ARGUMENT_NAME("Group name"),
791789
Argument::ARGUMENT_VALUE("Null"));
792790
}
@@ -795,7 +793,8 @@ void Config::checkPrivilegeMapper(const std::string& groupName)
795793
{
796794
if (val.second.get()->groupName() == groupName)
797795
{
798-
log<level::ERR>("Group name already exists");
796+
lg2::error("Group name '{GROUPNAME}' already exists", "GROUPNAME",
797+
groupName);
799798
elog<PrivilegeMappingExists>();
800799
}
801800
}
@@ -805,15 +804,15 @@ void Config::checkPrivilegeLevel(const std::string& privilege)
805804
{
806805
if (privilege.empty())
807806
{
808-
log<level::ERR>("Privilege level is empty");
807+
lg2::error("Privilege level is empty");
809808
elog<InvalidArgument>(Argument::ARGUMENT_NAME("Privilege level"),
810809
Argument::ARGUMENT_VALUE("Null"));
811810
}
812811

813812
if (std::find(privMgr.begin(), privMgr.end(), privilege) == privMgr.end())
814813
{
815-
log<level::ERR>("Invalid privilege");
816-
elog<InvalidArgument>(Argument::ARGUMENT_NAME("Privilege level"),
814+
lg2::error("Invalid privilege '{PRIVILEGE}'", "PRIVILEGE", privilege);
815+
elog<InvalidArgument>(Argument::ARGUMENT_NAME("Privilege"),
817816
Argument::ARGUMENT_VALUE(privilege.c_str()));
818817
}
819818
}

phosphor-ldap-config/ldap_config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <phosphor-logging/elog-errors.hpp>
88
#include <phosphor-logging/elog.hpp>
9-
#include <phosphor-logging/log.hpp>
9+
#include <phosphor-logging/lg2.hpp>
1010
#include <sdbusplus/bus.hpp>
1111
#include <sdbusplus/server/object.hpp>
1212
#include <xyz/openbmc_project/Common/error.hpp>

phosphor-ldap-config/ldap_config_mgr.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ constexpr auto nscdService = "nscd.service";
1717
constexpr auto ldapScheme = "ldap";
1818
constexpr auto ldapsScheme = "ldaps";
1919

20-
using namespace phosphor::logging;
2120
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
2221
namespace fs = std::filesystem;
2322
using Argument = xyz::openbmc_project::Common::InvalidArgument;
@@ -52,9 +51,8 @@ void ConfigMgr::restartService(const std::string& service)
5251
}
5352
catch (const sdbusplus::exception_t& ex)
5453
{
55-
log<level::ERR>("Failed to restart service",
56-
entry("SERVICE=%s", service.c_str()),
57-
entry("ERR=%s", ex.what()));
54+
lg2::error("Failed to restart service {SERVICE}: {ERR}", "SERVICE",
55+
service, "ERR", ex);
5856
elog<InternalFailure>();
5957
}
6058
}
@@ -69,9 +67,8 @@ void ConfigMgr::stopService(const std::string& service)
6967
}
7068
catch (const sdbusplus::exception_t& ex)
7169
{
72-
log<level::ERR>("Failed to stop service",
73-
entry("SERVICE=%s", service.c_str()),
74-
entry("ERR=%s", ex.what()));
70+
lg2::error("Failed to stop service {SERVICE}: {ERR}", "SERVICE",
71+
service, "ERR", ex);
7572
elog<InternalFailure>();
7673
}
7774
}
@@ -94,31 +91,30 @@ std::string ConfigMgr::createConfig(
9491
}
9592
else
9693
{
97-
log<level::ERR>("bad LDAP Server URI",
98-
entry("LDAPSERVERURI=%s", ldapServerURI.c_str()));
94+
lg2::error("Bad LDAP Server URI {URI}", "URI", ldapServerURI);
9995
elog<InvalidArgument>(Argument::ARGUMENT_NAME("ldapServerURI"),
10096
Argument::ARGUMENT_VALUE(ldapServerURI.c_str()));
10197
}
10298

10399
if (secureLDAP && !fs::exists(tlsCacertFile.c_str()))
104100
{
105-
log<level::ERR>("LDAP server's CA certificate not provided",
106-
entry("TLSCACERTFILE=%s", tlsCacertFile.c_str()));
101+
lg2::error("LDAP server CA certificate not found at {PATH}", "PATH",
102+
tlsCacertFile);
107103
elog<NoCACertificate>();
108104
}
109105

110106
if (ldapBindDN.empty())
111107
{
112-
log<level::ERR>("Not a valid LDAP BINDDN",
113-
entry("LDAPBINDDN=%s", ldapBindDN.c_str()));
108+
lg2::error("'{BINDDN}' is not a valid LDAP BindDN", "BINDDN",
109+
ldapBindDN);
114110
elog<InvalidArgument>(Argument::ARGUMENT_NAME("LDAPBindDN"),
115111
Argument::ARGUMENT_VALUE(ldapBindDN.c_str()));
116112
}
117113

118114
if (ldapBaseDN.empty())
119115
{
120-
log<level::ERR>("Not a valid LDAP BASEDN",
121-
entry("LDAPBASEDN=%s", ldapBaseDN.c_str()));
116+
lg2::error("'{BASEDN}' is not a valid LDAP BaseDN", "BASEDN",
117+
ldapBaseDN);
122118
elog<InvalidArgument>(Argument::ARGUMENT_NAME("LDAPBaseDN"),
123119
Argument::ARGUMENT_VALUE(ldapBaseDN.c_str()));
124120
}

phosphor-ldap-config/ldap_config_mgr.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <phosphor-logging/elog-errors.hpp>
88
#include <phosphor-logging/elog.hpp>
9-
#include <phosphor-logging/log.hpp>
9+
#include <phosphor-logging/lg2.hpp>
1010
#include <sdbusplus/bus.hpp>
1111
#include <xyz/openbmc_project/Common/error.hpp>
1212
#include <xyz/openbmc_project/User/Ldap/Config/server.hpp>

phosphor-ldap-config/ldap_mapper_entry.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <phosphor-logging/elog-errors.hpp>
99
#include <phosphor-logging/elog.hpp>
10-
#include <phosphor-logging/log.hpp>
10+
#include <phosphor-logging/lg2.hpp>
1111
#include <xyz/openbmc_project/Common/error.hpp>
1212
#include <xyz/openbmc_project/User/Common/error.hpp>
1313

phosphor-ldap-config/ldap_mapper_serialize.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include <cereal/archives/binary.hpp>
66
#include <cereal/types/string.hpp>
7-
#include <phosphor-logging/log.hpp>
7+
#include <phosphor-logging/lg2.hpp>
88

99
#include <fstream>
1010

@@ -18,8 +18,6 @@ namespace phosphor
1818
namespace ldap
1919
{
2020

21-
using namespace phosphor::logging;
22-
2321
/** @brief Function required by Cereal to perform serialization.
2422
*
2523
* @tparam Archive - Cereal archive type (binary in this case).
@@ -82,13 +80,15 @@ bool deserialize(const fs::path& path, LDAPMapperEntry& entry)
8280
}
8381
catch (const cereal::Exception& e)
8482
{
85-
log<level::ERR>(e.what());
83+
lg2::error("Failed to deserialize {FILE}: {ERR}", "FILE", path, "ERR",
84+
e);
8685
fs::remove(path);
8786
return false;
8887
}
8988
catch (const std::length_error& e)
9089
{
91-
log<level::ERR>(e.what());
90+
lg2::error("Failed to deserialize {FILE}: {ERR}", "FILE", path, "ERR",
91+
e);
9292
fs::remove(path);
9393
return false;
9494
}

phosphor-ldap-config/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "ldap_config_mgr.hpp"
44

55
#include <phosphor-logging/elog-errors.hpp>
6-
#include <phosphor-logging/log.hpp>
6+
#include <phosphor-logging/lg2.hpp>
77
#include <sdbusplus/bus.hpp>
88
#include <xyz/openbmc_project/Common/error.hpp>
99

@@ -21,8 +21,8 @@ int main(int /*argc*/, char** /*argv*/)
2121
phosphor::ldap::defaultNslcdFile) ||
2222
!std::filesystem::exists(configDir / phosphor::ldap::nsSwitchFile))
2323
{
24-
log<level::ERR>("Error starting LDAP Config App, configfile(s) are "
25-
"missing, exiting!!!");
24+
lg2::error("Failed to start phosphor-ldap-manager, configfile(s) are "
25+
"missing");
2626
elog<InternalFailure>();
2727
}
2828
auto bus = sdbusplus::bus::new_default();

shadowlock.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#include <phosphor-logging/elog-errors.hpp>
77
#include <phosphor-logging/elog.hpp>
8-
#include <phosphor-logging/log.hpp>
8+
#include <phosphor-logging/lg2.hpp>
99
#include <xyz/openbmc_project/Common/error.hpp>
1010

1111
#include <cassert>
@@ -36,15 +36,15 @@ class Lock
3636
{
3737
if (!lckpwdf())
3838
{
39-
log<level::ERR>("Locking Shadow failed");
39+
lg2::error("Failed to lock shadow file");
4040
elog<InternalFailure>();
4141
}
4242
}
4343
~Lock()
4444
{
4545
if (!ulckpwdf())
4646
{
47-
log<level::ERR>("Un-Locking Shadow failed");
47+
lg2::error("Failed to unlock shadow file");
4848
elog<InternalFailure>();
4949
}
5050
}

test/ldap_config_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <sys/types.h>
77

88
#include <phosphor-logging/elog-errors.hpp>
9-
#include <phosphor-logging/log.hpp>
9+
#include <phosphor-logging/lg2.hpp>
1010
#include <sdbusplus/bus.hpp>
1111
#include <xyz/openbmc_project/Common/error.hpp>
1212
#include <xyz/openbmc_project/User/Common/error.hpp>

0 commit comments

Comments
 (0)