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

Log4J JUL adapter is using MessageFormat on String passed by java.util.function.Supplier<String>

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4, 2.4.1
    • Fix Version/s: 2.5
    • Component/s: JUL adapter
    • Labels:
      None
    • Environment:

      Window 7 Business 64 bit
      Java(TM) SE Runtime Environment (build 1.8.0_25-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
      (log4j-jul-2.4.jar, log4j-core-2.4.jar, log4j-api-2.4.jar)

      Description

      Log4J JUL is attempting to MessageFormat a String passed by java.util.logging.Logger.info(java.util.function.Supplier<String>) and fails with java.lang.IllegalArgumentException when the String contains { }.

      In the following example, line #2 will throw an IllegalArgumentException:

      // writing the configuration file on the fly for the purpose of this demo only
      try (java.io.PrintStream p = new java.io.PrintStream("./log4j-jul-test.xml")) {
          p.println("<Configuration/>");
      }
      
      // specifying the java.util.logging.LogManager implementation
      System.setProperty("java.util.logging.manager", "org.apache.logging.log4j.jul.LogManager");
      System.setProperty("log4j.configurationFile", "log4j-jul-test.xml");
      
      java.util.logging.LogManager.getLogManager().getLogger("test").severe("This 1st {will} be logged correctly by log4J");
      // output is: 11:15:40.492 [main] ERROR test - This 1st {will} be logged correctly by log4J
      
      java.util.logging.LogManager.getLogManager().getLogger("test").severe(() -> "This 2nd {will not} be logged correctly by log4J");
      // output is: 2015-10-10 11:15:40,523 main ERROR An exception occurred processing Appender Console java.lang.IllegalArgumentException: can't parse argument number: will not
      //    at java.text.MessageFormat.makeFormat(MessageFormat.java:1429)
      //    at java.text.MessageFormat.applyPattern(MessageFormat.java:479)

      See also example on http://stackoverflow.com/a/33050986/495987

        Attachments

          Activity

            People

            • Assignee:
              garydgregory Gary Gregory
              Reporter:
              mollix Michael Fortin
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: