ABHINAV RANA
ABHINAV RANA

Reputation: 67

Remote Logging using Log4j2

So i have this task to log activities to a file, but it has to be done remotely on the server side, Remote logging.

NOTE : Remote Logging has to be in latest version of Log4j2(2.10)

My task was simple

  1. Send logging info to a port.
  2. Log info from port to a file.

My Discoveries

  1. Socket Appender exist which help send info to a port. This is it, you dont need to create a client side code or anything.

Socket appender configuration in log4j2.properties

appender.socket.type = Socket
appender.socket.name= Socket_Appender
appender.socket.host = "IP address"
appender.socket.port = 8101
appender.socket.layout.type = SerializedLayout
appender.socket.connectTimeoutMillis = 2000
appender.socket.reconnectionDelayMillis = 1000
appender.socket.protocol = TCP

Adapting from here. But this is also log4j 1.x adaptation.

  1. I found out that before log4j 2.6 to listen to a port we used TcpSocketServer which started a server using LogEventBridgeThis helped reach that conclusion. This class was in core.net.server which is no longer available.Assuming it is not used anymore and the only similar/closest class, TcpSocketManager.Other links that helped. How to use SocketAppend?
  2. Then i tried this

    public static final Logger LOG=LogManager.getLogger(myapp.class.getName());
    
    main(){
    LOG.debug("DEBUG LEVEL");
    }
    

and got the following error

main ERROR TcpSocketManager (TCP:IPAddress:8111) caught exception and will continue: java.net.SocketTimeoutException: connect timed out

I know this work because i made it read to a socket but there was no one listening, but somehow i messed up big time and there was a code change.

I need help how to go ahead. Thank You in advance

Upvotes: 2

Views: 5647

Answers (1)

Remko Popma
Remko Popma

Reputation: 36754

The socket server to remotely receive log events has been moved to a separate repository: https://github.com/apache/logging-log4j-tools

This still needs to be released.

Upvotes: 4

Related Questions