//---------------------------------------------------- // This javascript class is for creating a log window that can // be used on the client for displaying log information. A variety // of functions exist for inserting log lines and taking timings // of processes from the client side. This was developed initially // to help with benchmarking, as dialog interactions in some cases // artificially slow down the process a great deal. // Generally speaking, one instantiates an instance of the log // window, which creates a new window or returns an existing // instance if the specified window already exists. Then the various // logging methods can be called to add information to the log file. // in addition to simply logging events, this log can be used to time // processes. Here is an example: // LogWin = new LogWindow(); - gets instance of object // LogWin.InitializeTimingLog(); - sets timer to the current time // LogWin.AddBlankLogLine(); - add a blank line to the log // LogWin.AddBlankLogLine(); // LogWin.AddTimingLogLine( 'Start my process'); - adds a line and the current time // ... // LogWin.AddTimingLogLine( 'Called process'); // LogWin.WriteTotalTime( 'All done'); - notes total time elapsed from last call to IntializeTimingLog //---------------------------------------------------- //---------------------------------------------------- // Constructor for the LogWindow class to be used from the // the client side to log progress. This was initially written // for doing benchmarking type logging. // Input: Both parameters are optional // LogName - name of the log. This is used as the window so when new // references are created, the same window can be used to // log information multiple times. This parameter should be // all alphanumeric. No whitespace, no funny characters. // WindowTitle - Title that will show up in the browser. This can be // any string that would normally show up in a broswer window // title //---------------------------------------------------- function LogWindow(LogName, WindowTitle) { //fill in default parameters if necessary (no parameters passed in) if (arguments.length < 1) { LogName = "GenericLog" WindowTitle = "Generic Log" } else if (arguments.length < 2) { WindowTitle = "Generic Log" } //check for blanks. Can be passed in to take default names if (LogName == "") { LogName = "GenericLog" } if (WindowTitle == "") { WindowTitle = "Generic Log" } //set properties based on parameters passed in and get reference to window for logging this.LogName = LogName; this.Title = WindowTitle; this.NewLogWindow = window.open("",this.LogName,"height=400,width=500,menubar,resizable,scrollbars,status,toolbar"); //if there is no title to this window, it is new and we need to create it. //One thing we add is a hidden input field used for doing timings if (this.NewLogWindow.document.title == "") { StartTime = new Date(); //intialize content of window and write out start time this.NewLogWindow.document.write('' + this.Title + '\r\n
'); this.InitializeTimingLog(); } }// end LogWindow() constructor //add function references to the prototype object so they are available //from all instances LogWindow.prototype.InitializeTimingLog = LogWindow_InitializeTimingLog; LogWindow.prototype.AddTimingLogLine = LogWindow_AddTimingLogLine; LogWindow.prototype.AddLogLine = LogWindow_AddLogLine; LogWindow.prototype.WriteTotalTime = LogWindow_WriteTotalTime; LogWindow.prototype.AddBlankLogLine = LogWindow_AddBlankLogLine; //---------------------------------------------------- //resets the StartTime hidden input field for doing a timing of a process //---------------------------------------------------- function LogWindow_InitializeTimingLog() { StartTime = new Date(); this.NewLogWindow.document.all.StartTime.value = StartTime.getTime() } //---------------------------------------------------- //adds a log line, complete with current date and time information //---------------------------------------------------- function LogWindow_AddTimingLogLine(LineToAdd) { CurrTime = new Date() // if no argument passed in, default to empty string if (arguments.length < 1) { LineToAdd = "" } this.NewLogWindow.document.all.TimeLog.innerHTML = this.NewLogWindow.document.all.TimeLog.innerHTML + CurrTime.toString() + ':' + LineToAdd + '
\r\n'; } //---------------------------------------------------- //Adds whatever text you tell it to to the next line in the log //---------------------------------------------------- function LogWindow_AddLogLine(LineToAdd) { // if no argument passed in, default to empty string if (arguments.length < 1) { LineToAdd = ''; } this.NewLogWindow.document.all.TimeLog.innerHTML = this.NewLogWindow.document.all.TimeLog.innerHTML + LineToAdd + '
\r\n'; } //---------------------------------------------------- //writes a line that is the result of the current time minus the //value in the StartTime hidden input field. This is displayed in seconds //---------------------------------------------------- function LogWindow_WriteTotalTime(LineToAdd) { CurrTime = new Date(); var TotalTime =(CurrTime.getTime() - parseInt(this.NewLogWindow.document.all.StartTime.value))/1000; // if no argument passed in, default to empty string if (arguments.length < 1) { LineToAdd = "" } //otherwise, add a separator so the text doesn't show up immediately after the total time else { LineToAdd = ' - ' + LineToAdd; } this.AddTimingLogLine('Total Time:' + TotalTime + " seconds" + LineToAdd); } //---------------------------------------------------- //Adds a log line that is completely empty. //---------------------------------------------------- function LogWindow_AddBlankLogLine() { this.NewLogWindow.document.all.TimeLog.innerHTML = this.NewLogWindow.document.all.TimeLog.innerHTML + '
\r\n'; }