SadiJr commented on code in PR #7228:
URL: https://github.com/apache/cloudstack/pull/7228#discussion_r1113120157
##########
utils/src/main/java/com/cloud/utils/LogUtils.java:
##########
@@ -78,21 +79,29 @@ public static Set<String> getLogFileNames() {
return fileNames;
}
+ /**
+ * Tries to convert message parameters to JSON format and use them in the
message.
+ * @param formatMessage message to format.
+ * @param objects objects to convert to JSON. An null object will be
defaulted to the String "null";
+ * if it is not possible to convert an object to JSON, the object's
'toString' will be used instead.
+ * @return the formatted message.
+ */
public static String logGsonWithoutException(String formatMessage, Object
... objects) {
List<String> gsons = new ArrayList<>();
for (Object object : objects) {
try {
gsons.add(GSON.toJson(object));
} catch (Exception e) {
- LOGGER.debug(String.format("Failed to log object [%s] using
GSON.", object != null ? object.getClass().getSimpleName() : "null"));
- gsons.add("error to decode");
+ Object errObj = ObjectUtils.defaultIfNull(object, "null");
+ LOGGER.trace(String.format("Failed to log object [%s] using
GSON.", errObj.getClass().getSimpleName()));
+ gsons.add(errObj.toString());
}
}
try {
return String.format(formatMessage, gsons.toArray());
} catch (Exception e) {
String errorMsg = String.format("Failed to log objects using GSON
due to: [%s].", e.getMessage());
- LOGGER.error(errorMsg, e);
+ LOGGER.trace(errorMsg, e);
Review Comment:
@DaanHoogland As this message occurs when an object is not being converted
correctly to JSON (happens quite often with VMWare SDK objects) and does not
mean an exception or error/warning in the environment, I think putting the log
as warning might unnecessarily aware the operators.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]