Bug of log4j when log empty Map

Viewed 285
<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.14.1</version>
</dependency>

Java Codes:

    Logger logger = LogManager.getLogger();
    Map<String, String> map = new HashMap<>();
    System.out.println(logger);
    logger.info("{}-{}", System.currentTimeMillis(), map);

Output:

org.apache.logging.slf4j.SLF4JLogger@1c2c22f3
20:12:56.257 [main] INFO com.xxx - 1639051976254-1639051976254

Obviously, the correct output should be 1639051976254-{} Does any body have the same issue?

1 Answers

Yes, this is a known bug: LOG4J2-2623. Your message is formatted twice:

  • the first time by Log4j 2.x,
  • the second time by whatever SLF4J backend you are using (probably Logback).
Related