5

Could you recommend simple tutorial about using log4j in distributed system, especially about SocketAppender?

I tried to find some basic examples, but I failed.

alicjasalamon
  • 4,171
  • 15
  • 41
  • 65

1 Answers1

5

This one looks simple and straightforward. From the article:

Example server startup with SimpleSocketServer (from the command line):

> java -jar log4j.jar org.apache.log4j.net.SimpleSocketServer 4712 log4j-server.properties

Now all you have to do is specify your appender on the client.

Example appender:

> log4j.appender.SERVER=org.apache.log4j.net.SocketAppender
> log4j.appender.SERVER.Port=4712
> log4j.appender.SERVER.RemoteHost=loghost
> log4j.appender.SERVER.ReconnectionDelay=10000
oers
  • 18,436
  • 13
  • 66
  • 75
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
  • I still don't get it. I created [new question](http://stackoverflow.com/questions/11759196/log4j-how-to-use-socketappender) with more details – alicjasalamon Aug 01 '12 at 12:32
  • @trebuchet I edited the answer to clarify the startup of the server. If this answers your new question, please consider removing it – oers Aug 01 '12 at 12:41
  • Is it performance intensive? Or it's better to use a shell script? Like http://www.netfort.gr.jp/~dancer – Priyanshu Chauhan Jun 22 '15 at 12:04
  • I've never found it an issue, but as always, YMMV, and you should measure against your particular scenario – Brian Agnew Jun 22 '15 at 15:57
  • as Log4J 1.2 has reached end of life, is there a compatible solution with Log4J 2 SocketAppender ? It seems there is no SocketServer anymore.. – Donatello Jan 25 '18 at 12:06
  • @Donatello you can use FileBeats with ELK stack – Yasitha Bandara Feb 24 '22 at 12:03
  • @YasithaBandara yes, we are using EFK stack (FluentD) with JSON Template Layout from Log4j2. This is good for long history, but practically not so usable to do complex analysis... that's why I was looking for some alternative based on Socket appender – Donatello Feb 25 '22 at 18:13