Search code examples
logback

How to add an encoder for socket appender


I am using Logback socket appender, and everything is ok, I can get log from socket.

My scenario is: we have a distributed app, all logs will be saved into to a log server's log file with SocketAppender. I just use SimpleSocketServer provided in Logback to get log from all apps. And the logs can be got and saved.

But, the only problem is, for socket appender, no encoder can be added, and the log message will be formatted maybe in some default format. But I must save them in some format.

A way I can find is to write a log server like SimpleSocketServer, and the log server will get the serialized object (ILoggingEvent), and format the object myself.

But in this way, I need to write too many codes. I think there should be one convenient way to add a encoder.


Solution

  • I don't think you need to worry about the serialized version. You will give the SocketAppender on the various clients String messages.

    Then, so long as you configure the SimpleSocketServer to use the your desired Encoder in its configuration, all your messages should be in the correct format on disk.