libpldmresponder: Improving Logs (lg2)
This commit corrects the severity level of logs and also formats the
message string, fixing the ill-defined message string of the logs as
mentioned in the anti-pattern document [1]. Additionally, based on the
requirement this commit adds more debug information to logs.
[1]: https://github.com/openbmc/docs/blob/master/anti-patterns.md#ill-defined-data-structuring-in-lg2-message-strings
Change-Id: I7dc5c308a8cd76573995e07d01d1a6037bca31ba
Signed-off-by: Riya Dixit <riyadixitagra@gmail.com>
diff --git a/libpldmresponder/bios_string_attribute.cpp b/libpldmresponder/bios_string_attribute.cpp
index 28dde14..d52cdc4 100644
--- a/libpldmresponder/bios_string_attribute.cpp
+++ b/libpldmresponder/bios_string_attribute.cpp
@@ -25,9 +25,8 @@
auto iter = strTypeMap.find(strTypeTmp);
if (iter == strTypeMap.end())
{
- error(
- "Wrong string type, STRING_TYPE={STR_TYPE} ATTRIBUTE_NAME={ATTR_NAME}",
- "STR_TYP", strTypeTmp, "ATTR_NAME", name);
+ error("Wrong string type '{TYPE}' for attribute '{ATTRIBUTE}'", "TYPE",
+ strTypeTmp, "ATTRIBUTE", name);
throw std::invalid_argument("Wrong string type");
}
stringInfo.stringType = static_cast<uint8_t>(iter->second);
@@ -52,10 +51,11 @@
if (rc != PLDM_SUCCESS)
{
error(
- "Wrong field for string attribute, ATTRIBUTE_NAME={ATTR_NAME} ERRMSG={ERR_MSG} MINIMUM_STRING_LENGTH={MIN_LEN} MAXIMUM_STRING_LENGTH={MAX_LEN} DEFAULT_STRING_LENGTH={DEF_LEN} DEFAULT_STRING={DEF_STR}",
- "ATTR_NAME", name, "ERR_MSG", errmsg, "MIN_LEN",
- stringInfo.minLength, "MAX_LEN", stringInfo.maxLength, "DEF_LEN",
- stringInfo.defLength, "DEF_STR", stringInfo.defString);
+ "Wrong field for string attribute '{ATTRIBUTE}', error '{ERROR}', minimum string length '{MINIMUM_STRING_LENGTH}', maximum string length '{MAXIMUM_STRING_LENGTH}', default string length '{DEFAULT_STRING_LENGTH}' and default string '{DEFAULT_STRING}'",
+ "ATTRIBUTE", name, "ERROR", errmsg, "MINIMUM_STRING_LENGTH",
+ stringInfo.minLength, "MAXIMUM_STRING_LENGTH", stringInfo.maxLength,
+ "DEFAULT_STRING_LENGTH", stringInfo.defLength, "DEFAULT_STRING",
+ stringInfo.defString);
throw std::invalid_argument("Wrong field for string attribute");
}
}
@@ -89,8 +89,9 @@
catch (const std::exception& e)
{
error(
- "Error getting string attribute '{ATTR}' from '{INTERFACE}': {ERROR}",
- "ATTR", name, "INTERFACE", dBusMap->interface, "ERROR", e);
+ "Failed to get string attribute '{ATTRIBUTE}' at path '{PATH}' and interface '{INTERFACE}' for property '{PROPERTY}', error - {ERROR}",
+ "ATTRIBUTE", name, "PATH", dBusMap->objectPath, "INTERFACE",
+ dBusMap->interface, "PROPERTY", dBusMap->propertyName, "ERROR", e);
return stringInfo.defString;
}
}
@@ -145,8 +146,7 @@
}
catch (const std::bad_variant_access& e)
{
- error("invalid value passed for the property, error: {ERR_EXCEP}",
- "ERR_EXCEP", e.what());
+ error("Invalid value passed for the property - {ERROR}", "ERROR", e);
return PLDM_ERROR;
}
return PLDM_SUCCESS;