I’ve got an answer about how to use SocketAppender (I need it to gather logs from distributed system), but I am new to log4j and I have no idea how to use that sample code.
Probably I should have log4j-server.properties like that:
log4j.appender.SERVER=org.apache.log4j.net.SocketAppender
log4j.appender.SA.Port=4712
log4j.appender.SA.RemoteHost=loghost
log4j.appender.SA.ReconnectionDelay=10000
But I still don’t know how to start the server (how to use this line)
org.apache.log4j.net.SimpleSocketServer 4712 log4j-server.properties
And what is the most important:
Where\How can I see my logs?
You can run the server using
The
SimpleSocketServerreceives logging events sent to the specified port number by the remoteSocketAppender, and logs them as if they were generated locally, according to the configuration you supply inlog4j-server.properties. It’s up to you to configure the relevant console/file/rolling file appenders and attach them to the relevant loggers just as you would if you were doing the logging directly in the original process rather than piping the log events over a network socket. I.e. if you’re currently creating local log files with something like:then you would change it so that the sending side
log4j.propertiessimply saysand the server-side
log4j-server.propertiescontains the definitions that were previously on the sending side:In particular, note that there’s no point specifying a layout on the
SocketAppenderon the sending side – what goes over the network is the whole logging event object, it’s the receiving side that is responsible for doing the layout.