You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Sharif Rahaman (JIRA)" <ji...@apache.org> on 2019/02/22 20:37:00 UTC

[jira] [Commented] (LOG4J2-1969) TcpSocketServer does not replace any “{}” in message

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

Sharif Rahaman commented on LOG4J2-1969:
----------------------------------------

Running with --classes arguments is working in Windows OS but not in Linux. I am running below commands in Linux OS:
{code:java}
java -classpath log4j-core-2.8.2.jar:log4j-api-2.8.2.jar:jcommander-1.48.jar org.apache.logging.log4j.core.net.server.TcpSocketServer -p 9898 -c log4j2-postman.xml --classes java.util.Collections$UnmodifiableMap --classes java.util.HashMap
{code}
Which is resulting:
{code:java}
22 Feb 2019 12:23:41,620 ERROR 9898:94 - IOException encountered while reading from socket java.io.InvalidObjectException: Class is not allowed for deserialization: java.util.Collections$UnmodifiableMap
at org.apache.logging.log4j.core.util.FilteredObjectInputStream.resolveClass(FilteredObjectInputStream.java:56) ~[log4j-core-2.8.2.jar:2.8.2]
{code}
Would you please help.

> 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
>            Priority: Major
>             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
(v7.6.3#76005)