Send logs from a REST service to an HTML page

I have a REST service on a server A. The service is doing some stuff and logging some messages thanks to log4j.

Aside, I have a web page on server B that is calling the service thanks to AJAX and getting the response. Apart from receiving the response (which works fine to me), I would like to print on the page the log messages from the server side.

In other words, I would like that every time there is a new log message on server A side, the view display it.

Any ideas to achieve that ?

EDIT:
How to use a websocket to retrieve logs from a log4j socket appender?

Answer

I finally found a way to solve my problem:

I have created a singleton logger. Every time I want to log a message, I am getting the instance of the logger and add the new message to the ConcurrentLinkedList of logs.

On the other hand, I have created a new rest service. Every second I call this service with an ajax query. It removes the log messages of the list and return them. The view display them.

Leave a Reply

Your email address will not be published. Required fields are marked *