logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Remko Popma (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (LOG4J2-632) Formatter logger mixes up arguments
Date Wed, 06 Aug 2014 05:47:12 GMT

     [ https://issues.apache.org/jira/browse/LOG4J2-632?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Remko Popma resolved LOG4J2-632.
--------------------------------

    Resolution: Not a Problem

Problem is in the format string as Ralph indicated.
{code}
public class StrFormat {
  public static void main(String[] args) {
    String fmt1 = "It is %1s in %2s";
    String fmt2 = "It is %1$tF in %2s";
    String fmt3 = "It is %1$tF in %2$s";
    
    System.out.println(String.format(fmt1, new Date(), "Switzerland"));
    System.out.println(String.format(fmt2, new Date(), "Switzerland"));
    System.out.println(String.format(fmt3, new Date(), "Switzerland"));
  }
}
{code}

Output:
{code}
It is Wed Aug 06 14:43:42 JST 2014 in Switzerland
It is 2014-08-06 in Wed Aug 06 14:43:42 JST 2014
It is 2014-08-06 in Switzerland
{code}


> Formatter logger mixes up arguments
> -----------------------------------
>
>                 Key: LOG4J2-632
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-632
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.0-rc1
>            Reporter: Alexandre Gattiker
>
> {code}
> public class Example {
> 	private final static Logger FORMATTER_LOGGER = LogManager.getFormatterLogger(Example.class);
> 	public static void main(String[] args) {
> 		FORMATTER_LOGGER.log(ERROR, "It is %1s in %2s", new Date(), "Switzerland"); // works
fine
> 		FORMATTER_LOGGER.log(ERROR, "It is %1$tF in %2s", new Date(), "Switzerland"); // ignores
"Switzerland", uses %1 value instead
> 	}
> }
> {code}
> {noformat}
> 13:53:21.350 [main] ERROR com.example.Example - It is Tue May 06 13:53:21 CEST 2014 in
Switzerland
> 13:53:21.355 [main] ERROR com.example.Example - It is 2014-05-06 in Tue May 06 13:53:21
CEST 2014
> {noformat}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
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