Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-1969

TcpSocketServer does not replace any “{}” in message

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.2, 2.7
    • 2.8
    • Appenders
    • None
    • Spring boot 1.5.4
      java 8

    Description

      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:

          logger.info("Request from [{}] to [{}]", ipInfo, reqPath);
      

      The `RollingfileAppender` and `ConsoleAppender` will output:

          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] 
      

      But the `SocketAppender` just ouput:

          INFO  2017-07-06 16:46:07,929 [127.0.0.1][/senten/align] AuthFilter (http-nio-8180-exec-2) Request from [{}] to [{}] 
      

      This is my config with `SocketAppenders` in log4j.xml

              <Appenders>
      		<Socket name="socket" host="127.0.0.1" port="9898">
      			<SerializedLayout />
      		</Socket>
              ........
      	</Appenders>
      

      This is my config file `log4j2-socket.xml` for `TcpSocketServer`:

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

      And, I use this command for start `TcpSocketServer`:

          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
      

      What am I doing wrong? How to fix it? Thanks!

      Attachments

        Activity

          People

            Unassigned Unassigned
            huache YU Chang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: