Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1368

Status logger drops/ignores exception

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5
    • Fix Version/s: 2.6
    • Component/s: API
    • Labels:
      None

      Description

      Internal log4j logging like below will just log the message but will not report the specified exception:

      try {
          someProcess();
      } catch (Exception exception) {
          StatusLogger.getLogger().warn("error occurred during {}", "some process", exception);
      }
      

      This is caused by a bug in ParameterizedNoReferenceMessageFactory (the factory used by StatusLogger):

      final String formatted = new ParameterizedMessage(message, params).getFormattedMessage();
      return new SimpleMessage(formatted); // exception is dropped
      

      This factory was introduced to resolve memory leaks that appeared in web containers because StatusLogger keeps a ring buffer of previously logged messages and ParameterizedMessage keeps a reference to its parameter objects (LOG4J2-1176).

      AbstractLogger depends on the Message to get the Throwable when logging a message with parameters, so SimpleMessage is not good enough. I'm thinking to introduce a new class StatusMessage (perhaps as an inner class of ParameterizedNoReferenceMessageFactory in order to keep the API surface small). StatusMessage would have the formatted string and the Throwable (which may be null). That should solve this issue.

      If the Throwable is a custom Log4j class like AppenderLoggingException then keeping a reference to it may re-introduce memory leaks again though, but I guess that is a fight for another day...

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                remkop@yahoo.com Remko Popma
                Reporter:
                remkop@yahoo.com Remko Popma
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: