Uploaded image for project: 'logback'
  1. logback
  2. LOGBACK-1215

Logger string interpolation fails if exception is the last argument despite correct number of "{}"

    XMLWordPrintable

Details

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • None
    • None
    • logback-core

    Description

      It's known that:

      logger.error("String {} with {} some {} arguments, object1, object2, object3, exception);
      

      will correctly interpolate the three objects' object.toString() where the " {} " exist in the string.

      However, this will produce unintuitive behavior:

      logger.error("String {} with {} some {} arguments, object1, object2, exception);
      

      Expected behavior: the string is interpolated properly, with the third argument being the result of exception.toString()
      Actual behavior: the third " {} " literally prints out " {} ".

      This is worse if you're trying to print multiple exceptions:

      logger.error("Exception 1: {}, Exception 2: {}", exception1, exception2);
      

      This will have the very unintuitive behavior of printing this, essentially leaving the "{}" in the string.

      "Exception 1: {}, Exception 2: {}"
      

      Attachments

        Activity

          People

            logback-dev Logback dev list
            navkast Naveen Kasthuri
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: