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

Mikael Ståldal closed LOG4J2-1969.
----------------------------------

> TcpSocketServer does not replace any “{}” in message
> ----------------------------------------------------
>
>                 Key: LOG4J2-1969
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1969
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Appenders
>    Affects Versions: 2.6.2, 2.7
>         Environment: Spring boot 1.5.4
> java 8
>            Reporter: YU Chang
>             Fix For: 2.8
>
>
> I have a spring boot(v1.5.4) web application which use log4j-2.7 for logging.
> It works well when write log message to file or console, but when send 
> message to `TcpSocketServer`, the log server just output the message without 
> the "{}" formatting. for example, for this code:
> {code:java}
>     logger.info("Request from [{}] to [{}]", ipInfo, reqPath);
> {code}
> The `RollingfileAppender` and `ConsoleAppender` will output:
> {code:none}
>     INFO  2017-07-06 16:46:07,929 [127.0.0.1][/senten/align] AuthFilter 
> (http-nio-8180-exec-2) Request from [127.0.0.1] to [/senten/align] 
> {code}
> But the `SocketAppender` just ouput:
> {code:none}
>     INFO  2017-07-06 16:46:07,929 [127.0.0.1][/senten/align] AuthFilter 
> (http-nio-8180-exec-2) Request from [{}] to [{}] 
> {code}
> This is my config with `SocketAppenders` in log4j.xml
> {code:xml}
>         <Appenders>
>               <Socket name="socket" host="127.0.0.1" port="9898">
>                       <SerializedLayout />
>               </Socket>
>         ........
>       </Appenders>
> {code}
> This is my config file `log4j2-socket.xml` for `TcpSocketServer`:
> {code:xml}
>     <Configuration status="WARN">
>       <Appenders>
>               <RollingFile name="default" fileName="Logs/app.log"
>                       
> filePattern="Logs/${date:yyyy-MM}/app-%d{yyyy-MM-dd}-%i.log.gz">
>                       <PatternLayout>
>                               <Pattern>%-5p %d [%X{ip}][%X{reqPath}] %c{1} 
> (%t) %m %ex%n</Pattern>
>                       </PatternLayout>
>                       <Policies>
>                               <TimeBasedTriggeringPolicy interval = "30" 
> modulate="true"/>
>                               <SizeBasedTriggeringPolicy size="200 MB" />
>                       </Policies>
>               </RollingFile>
>       </Appenders>
>       <Loggers>
>               <Root level="DEBUG">
>                       <AppenderRef ref="default" level="DEBUG" />
>               </Root>
>       </Loggers>
>     </Configuration>
> {code}
> And, I use this command for start `TcpSocketServer`:
> {code:none}
>     java -classpath log4j-core-2.7.jar:log4j-api-2.7.jar:jcommander-1.48.jar 
> org.apache.logging.log4j.core.net.server.TcpSocketServer -p 9898 -c 
> log4j2-socket.xml
> {code}
> What am I doing wrong? How to fix it? Thanks!
>  



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

Reply via email to