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

NumberFormatException when using log4j-jul

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Critical
    • Resolution: Duplicate
    • 2.5
    • 2.6
    • JUL adapter
    • None

    Description

      I am using CXF to provide REST services and it generates logs using JUL. I wanted to redirect the output of those logs to Log4j2 because I am already using it in my application.

      I managed to create a test case that replicates the problem:

      The JVM is started with:

      -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager

      This is the code, based on CXF code (which works with JUL):

      String message = "Inbound Message\n" +
      "----------------------------\n" +
      "ID: 5\n" +
      "Address: https://localhost:8443/admin-api/rest/client/users\n" +
      "Encoding: ISO-8859-1\n" +
      "Http-Method: POST\n" +
      "Content-Type: application/json\n" +
      "Headers:

      {Accept=[application/json], adminuser=[constantino.cronemberger@xyz.com], Authorization=[Basic dGVzdC1hcHA6UGFzc3dvcmRAMTIz], cache-control=[no-cache], connection=[keep-alive], Content-Length=[216], content-type=[application/json], host=[localhost:8443], pragma=[no-cache], user-agent=[Apache CXF 3.1.5]}

      \n" +
      "Payload:

      {\"email\":\"constantino.cronemberger@xyz.com\",\"firstName\":\"Constantino\",\"lastName\":\"Cronemberger\",\"phone\":\"+11 11 1111-1111\",\"source\":\"INTERNAL_STORAGE\",\"phone2\":null,\"fax\":null,\"address\":null,\"status\":\"A\",\"clientId\":2}

      \n" +
      "--------------------------------------";
      java.util.logging.Logger logger = java.util.logging.Logger.getLogger("test123");
      LogRecord lr = new LogRecord(Level.INFO, message);
      lr.setSourceClassName(logger.getName());
      lr.setSourceMethodName(null);
      lr.setLoggerName(logger.getName());
      logger.log(lr);

      And this is the exception:

      2016-02-23 14:24:27,663 main ERROR An exception occurred processing Appender appLog java.lang.IllegalArgumentException: can't parse argument number: Accept=[application/json]
      at java.text.MessageFormat.makeFormat(MessageFormat.java:1429)
      at java.text.MessageFormat.applyPattern(MessageFormat.java:479)
      at java.text.MessageFormat.<init>(MessageFormat.java:362)
      at java.text.MessageFormat.format(MessageFormat.java:840)
      at org.apache.logging.log4j.message.MessageFormatMessage.formatMessage(MessageFormatMessage.java:94)
      at org.apache.logging.log4j.message.MessageFormatMessage.getFormattedMessage(MessageFormatMessage.java:66)
      at org.apache.logging.log4j.core.pattern.MessagePatternConverter.format(MessagePatternConverter.java:68)
      at org.apache.logging.log4j.core.pattern.PatternFormatter.format(PatternFormatter.java:36)
      at org.apache.logging.log4j.core.layout.PatternLayout$PatternSerializer.toSerializable(PatternLayout.java:292)
      at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:206)
      at org.apache.logging.log4j.core.layout.PatternLayout.toSerializable(PatternLayout.java:56)
      at org.apache.logging.log4j.core.layout.AbstractStringLayout.toByteArray(AbstractStringLayout.java:148)
      at org.apache.logging.log4j.core.appender.AbstractOutputStreamAppender.append(AbstractOutputStreamAppender.java:112)
      at org.apache.logging.log4j.core.appender.RollingFileAppender.append(RollingFileAppender.java:88)
      at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:152)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:125)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:116)
      at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84)
      at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:390)
      at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:378)
      at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:362)
      at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:352)
      at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:63)
      at org.apache.logging.log4j.core.Logger.logMessage(Logger.java:147)
      at org.apache.logging.log4j.spi.ExtendedLoggerWrapper.logMessage(ExtendedLoggerWrapper.java:135)
      at org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:933)
      at org.apache.logging.log4j.jul.ApiLogger.log(ApiLogger.java:61)
      at com.xyz.api.server.dao.LoggingTest.realTest(LoggingTest.java:74)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:497)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
      Caused by: java.lang.NumberFormatException: For input string: "Accept=[application/json]"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
      at java.lang.Integer.parseInt(Integer.java:580)
      at java.lang.Integer.parseInt(Integer.java:615)
      at java.text.MessageFormat.makeFormat(MessageFormat.java:1427)
      ... 53 more

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ccronemberger Constantino Cronemberger
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: