You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@logging.apache.org by "Kostiantyn Shchepanovskyi (JIRA)" <ji...@apache.org> on 2017/09/05 15:05:00 UTC

[jira] [Commented] (LOG4J2-2032) Curly braces in parameters are treated as placeholders

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

Kostiantyn Shchepanovskyi commented on LOG4J2-2032:
---------------------------------------------------

It seems that placeholders are processed twice:

1. In {{org.apache.logging.log4j.core.config.LoggerConfig#log(java.lang.String, java.lang.String, org.apache.logging.log4j.Marker, org.apache.logging.log4j.Level, org.apache.logging.log4j.message.Message, java.lang.Throwable)}} - when we create {{LogEvent}} instance, {{LogEvent#getFormattedMessage()}} returns correct text.
2. In {{org.apache.logging.log4j.core.appender.AsyncAppender#append}} - when we create {{Log4jLogEvent}} from {{LogEvent}}, {{memento.getMessage().getFormattedMessage()}} returns incorrect text.

> Curly braces in parameters are treated as placeholders
> ------------------------------------------------------
>
>                 Key: LOG4J2-2032
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2032
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Layouts
>    Affects Versions: 2.8.2, 2.9.0
>         Environment: Tested on Windows and Linux.
> java version "1.8.0_144"
> Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
> Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)
>            Reporter: Kostiantyn Shchepanovskyi
>
> 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:
> {code:xml}
> <?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>
> {code}
> Test:
> {code:java}
> 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{}");
>     }
> }
> {code}
> Expected output:
> {code}
> 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]
> {code}
> Actual output:
> {code}
> 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]
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)