Reputation: 4419
I am trying to do some frontend logging using log4js and sending the logs using the AjaxAppender to the server backend using Java. This is the frontend code that I use to initialize the logger, I've made sure the logger works with a DefaultLogger, and switched to AjaxAppender.
var log = log4javascript.getLogger();
var ajaxAppender = new log4javascript.AjaxAppender("logger");
ajaxAppender.setTimed(true);
ajaxAppender.setTimerInterval(10000); // send every 10 seconds (unit is milliseconds)
log.addAppender(ajaxAppender);
//convert to JSON format
jsonLayout = new log4javascript.JsonLayout(false, false); //readable, combineMessages
ajaxAppender.setLayout(jsonLayout);
ajaxAppender.addHeader("Content-Type", "application/json");
log.info("Begin Session")
This is the backend code written in Java, which gets the logs sent from the frontend.
@RequestMapping(value = "/logger", method = RequestMethod.POST)
@ResponseBody
public String logger(HttpServletRequest request, HttpServletResponse response) throws InterruptedException, IOException, SQLException {
System.out.println("Inside Logger");
System.out.println("Log:"+request);
return "Test successful:" + request;
}
However, I am getting the error XHR failed loading POST and the code doesn't seem to go inside the logger function ("Inside Logger" is not printed in terminal). I'm fairly new to working with Ajax and sending request between frontend and backend, is there a reason why the XMLHttpRequest is not going through?
Thanks!
Upvotes: 0
Views: 898
Reputation: 48
404 means the service isn't reachable. Are you sure you've started the service and configged it properly?
Upvotes: 0