JavaScript log servlet 1.3

It is a Java servlet lets you log data right from your JavaScript code. Actually you can use Ajax for asynchronous transferring data from your JavaScript code to this servlet. Servlet will record them into log file as well as display via own GUI. You can use it as debug or monitoring tool for your JavaScript code.

How to use it:

a) copy jslogPackage.jar into your WEB-INF/lib directory.

b) define JSLogServlet in your web.xml file. You can set an optional initial parameter for this servlet. Parameter name is log. This parameter describes an existing directory for your log file (files). By default it will be / (a root directory):

    <param-value>path_to_your_log_file (directory)</param-value>

c) define a mapping:


d) download JavaScript file jslog.js and add it to your JSP (HTML) page:

<script language="JavaScript" src="jslog.js"></script>

JavaScript file adds own namespace jsLog and now in your JavaScript code you can use the following call:

jsLog.Info(your data)


jsLog.Info("x="+x); write string
jsLog.Info(x); write variable x. It could be JavaScript object too, all the properties will be saved
jsLog.Info(x,'var x'); write variable x and title.

Your data will be logged by the servlet. You can directly run servlet in the browser:


and see the logged data in real time. Servlet automatically reloads the newest data.

jsLog.Info() is actually an asynchronous (Ajax) call. By default Ajax request will use the following mapping for log servlet: /servlet/jsLog. Alternatively you may pass a path to log servlet as an additional parameter for jsLog.Info() (after the title) or set is via jsLog.setURL(your_url_for servlet) call.

Also your JavaScript code can dynamically switch on/off the logging. Use the following Javascript calls:


by default the logging is on.

    For downloading:   jslogPackage.jar     JavaScript library: jslog.js

 © Coldbeans Software     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in Coldtags & JSOS: