How to use Pattern layout with SocketAppender

2020-02-15 03:56发布

问题:

I read org.apache.log4j.net.SocketAppender does not use a Layout. But, I really need to format my logs and I need to use a ConversionPattern. Does anybody know an alternate to this? I have to use some kind of SocketAppender.

Thanks

回答1:

The logs sent through a SocketAppender are serialized and can't have a layout specified to it until it is deserialized. On the remote host you'll have access to all the same information and should be able to specify the layout that the logs are printed in. So the difference is only that you specify the layout on the other side.