2

I've been searching for any example of how to get the remote client's ip address printed in the log4j2 TcpSocketServer server side log file and I'm hoping I'm just not searching for the right thing. Is it possible to the remote client's ip and if so how?

If I use TcpSocketServer I can get this when the server starts up:

2017-04-10 11:30:31,316 [Log4j2-0] DEBUG [TcpSocketServer.java:231] Socket accepted: Socket[addr=/10.64.1.2,port=52412,localport=4560]

What I want is for the ip address to be somehow included on each logging line:

2017-04-10 11:30:31,316 [Log4j2-0] [10.64.1.2] DEBUG [MyFile.java:17] Test Logging line
kasdega
  • 17,656
  • 12
  • 41
  • 85
  • Couldn't you use the [ThreadContext](https://logging.apache.org/log4j/2.x/manual/thread-context.html)? Add the [appropriate IP address](http://stackoverflow.com/a/9482369/3284624) to the context and then add the variable to the pattern layout of the appender(s). – D.B. Apr 11 '17 at 02:14
  • I'm not sure. Do you have an example of how this would be configured? – kasdega Apr 12 '17 at 16:48
  • 1
    pls update with your resolution if you have resolved it. thx. – Leon Aug 05 '18 at 04:30

0 Answers0