Details
Description
When logging event parameter contains two consecutive opening and closing curly braces - for example {} in the middle of parameter, they are treated as a placeholder and are substituted by provided parameters starting from index zero.
I suspect that it affects only async loggers.
My configuration:
<?xml version="1.0" encoding="UTF-8"?> <Configuration> <Appenders> <Console name="console" target="SYSTEM_OUT"> <PatternLayout> <pattern>%level{length=1} %date{MMdd-HHmm:ss,SSS} %logger{1.} %message %X [%thread]%n </pattern> </PatternLayout> </Console> <Async name="asyncFile"> <AppenderRef ref="console"/> </Async> </Appenders> <Loggers> <Root level="info"> <AppenderRef ref="asyncFile"/> </Root> </Loggers> </Configuration>
Test:
package com.playtech.live.platform.core.service; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class Log4jCurlyBracesInParameterTest { private static final Logger LOGGER = LoggerFactory.getLogger(Log4jCurlyBracesInParameterTest.class); @Test void messageWithCurlyBracesInParameter() { LOGGER.info("Text containing curly braces: {}", "Curly{}"); LOGGER.info("Normal text: {}, text containing curly braces {}", "Normal", "Curly{}"); } }
Expected output:
I 0905-1731:01,018 c.p.l.p.c.s.Log4jCurlyBracesInParameterTest Text containing curly braces: Curly{} {} [main] I 0905-1731:01,033 c.p.l.p.c.s.Log4jCurlyBracesInParameterTest Normal text: Normal, text containing curly braces Curly{} {} [main]
Actual output:
I 0905-1731:01,018 c.p.l.p.c.s.Log4jCurlyBracesInParameterTest Text containing curly braces: CurlyCurly{} {} [main] I 0905-1731:01,033 c.p.l.p.c.s.Log4jCurlyBracesInParameterTest Normal text: Normal, text containing curly braces CurlyNormal {} [main]
Attachments
Issue Links
- is duplicated by
-
LOG4J2-2345 JsonLayout logs malformed if toString() contains empty curly braces {}
- Closed
- links to