|
MONK : Monk Event Logging Stack
This page last changed on Oct 19, 2007 by sgs@mcmaster.ca.
Javascript Logging Library / Java ServletOverview:Java / Javascript library to handle the logging of activity in a web-based environment. The library uses the 'prototype.js' (http://www.prototypejs.org/) javascript library to handle the AJAX server calls (this was an easy way to get really good, long lasting cross browser support for communication with a server). Download Link:The entire package is available as a '.zip' archive (634KB) from: http://www.digital-profiles.com/MONK_Workbench/MonkLogger.zip Package Contents:'Create Log Table.sql'This file contains SQL commands to create a table to store log data into. The created table will be named 'Logs', and it contains 7 fields:
'logger.html'This is a sample web page that displays a few buttons that fire log messages. This page also demonstrates the use of the logger debug div (named 'loggerDebug'). This gives us a way to output debug / status messages into any page that is using the logger. For debugging to work, it must be enabled in the 'logger.js' file (set the constant 'var debugEnabled' which can be found near the top of 'logger.js' to true). 'logger.js'This is the javascript library that handles the logging of events. This file depends on the 'prototype.js' javascript library. There are several global settings that can be adjusted in the 'logger.js':
'WEB-INF/src/LogEntry.java'Java class to represent a log entry. The java class also has a connivence method to export to MySQL:
It is also possible to create a java log entry from a Java MySQL ResultSet by using the public LogEntry (ResultSet rs) constructor. 'WEB-INF/src/SaveLogs.java'This is the Java servlet that handles the saving of data to a MySQL database. Being very dependent on the local MySQL setup, without modification the servlet does not actually save anything, but it does create 'LogEntry' Java objects that contains a public method 'toSQL()'. This method generates a MySQL insert statement that could be used to add the entry to the database. The servlet takes two arguments:
Example Usage: www.example.com/logManager.SaveLogs?TransactionID=UserID-1187834569242&Messages=1187834569240:EventType-UserID,EventDispatcher,EventDescription,EventArgs|1187834569241:EventType2-UserID,EventDispatcher2,EventDescription2,EventArgs2 Example Result: <SaveResult TransactionID="UserID-1187834569242" NumSaved="2"> 'WEB-INF/lib/mysql-connector-java-5.0.7-bin.jar'MySQL connector library for the Java servlet. 'WEB-INF/lib/servlet-api.jar'Java servlet library. 'WEB-INF/web.xml'Apache Tomcat servlet mapping. The saving servlet is mapped to 'logManager.SaveLogs'. Installation:To compile the Java servlet:javac -classpath lib/servlet-api.jar:lib/mysql-connector-java-5.0.7-bin.jar. src/*.java -d classes Usage:Logger Usage:Include both the 'prototype.js' and the 'logger.js' javascript files in your web page: <head> To Log an Event:Call the javascript function: log (userID, eventDispatcher, eventDescription, eventArguments, eventType); The logs will remain in a local javascript array until one of three conditions are met:
Error Handling:If an entire transaction fails to successfully upload to the server (i.e. the XML result indicates that NumSaved = 0), it is counted as a failure. After the constant 'var failureLimit' number of failures, the logger will disable itself. If a transaction partially fails (i.e. the XML result indicates that the number saved was less than the number sent), the logger will attempt to resend the lost entries.
|
| Document generated by Confluence on Apr 19, 2009 15:04 |