Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-4277

StandardLogRepository does not log exceptions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Patch Available
    • Major
    • Resolution: Unresolved
    • 1.3.0
    • None
    • Core Framework
    • None

    Description

      When logging a message, it is logged with the SLF4J logger and also stored in the standard log repository (for the bulletins). However if the array of objects contains the exception (and not the message of the exception), this exception won't be displayed in the bulletin message.

      That's because of:

      StandardLogRepository.java
          @Override
          public void addLogMessage(final LogLevel level, final String format, final Object[] params) {
              final String formattedMessage = MessageFormatter.arrayFormat(format, params).getMessage();
              addLogMessage(level, formattedMessage);
          }
      

      If the params object contains a Throwable object, it'll be removed from the array in the MessageFormatter:

      MessageFormatter.java
          final public static FormattingTuple arrayFormat(final String messagePattern, final Object[] argArray) {
              Throwable throwableCandidate = getThrowableCandidate(argArray);
              Object[] args = argArray;
              if (throwableCandidate != null) {
                  args = trimmedCopy(argArray);
              }
              return arrayFormat(messagePattern, args, throwableCandidate);
          }
      

      Easy solution would be to change:

      logger.debug("Failed to validate {} against schema due to {}", new Object[]{flowFile, e});
      

      into:

      logger.debug("Failed to validate {} against schema due to {}", new Object[]{flowFile, e.getLocalizedMessage()});
      

      However this pattern can be found in quite a large number of places... And it'd be certainly better to provide a permanent solution supporting the existing pattern. Suggestion is to modify the method in StandardLogRepository to go through all the items of the array and for each Throwable object, replace it by the localized message.

      Attachments

        Issue Links

          Activity

            People

              pvillard Pierre Villard
              pvillard Pierre Villard
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated: