DaanHoogland commented on code in PR #7228:
URL: https://github.com/apache/cloudstack/pull/7228#discussion_r1113160839


##########
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:
   fair enough



-- 
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]

Reply via email to