logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ralph Goers (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1158) Log4J JUL adapter is using MessageFormat on String passed by java.util.function.Supplier<String>
Date Wed, 14 Oct 2015 00:34:05 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1158?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14956018#comment-14956018
] 

Ralph Goers commented on LOG4J2-1158:
-------------------------------------

I think it might be a mistake to just use SimpleMessage for this. I would think that using
FormattedMessage might make more sense here. It still allows for logEvents that expect to
use MessageFormat but should avoid the exception being complained about here.

It would be nice if there was some way to configure which MessageFactory to use.

> Log4J JUL adapter is using MessageFormat on String passed by java.util.function.Supplier<String>
> ------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1158
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1158
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: JUL adapter
>    Affects Versions: 2.4, 2.4.1
>         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)
>            Reporter: Michael Fortin
>            Assignee: Gary Gregory
>            Priority: Minor
>             Fix For: 2.5
>
>
> 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*_:
> {code:java}// 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){code}
> See also example on http://stackoverflow.com/a/33050986/495987



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message