In Java Web development, we are more commonly used by log4j in the server, but in the customer, but use Alert to take the result of the middle result, it is very inconvenient. For this, I organize a client through JavaScript. To make a write log script, its use method is similar to the log4j. 1.javascript Write the log component script, you can put it in a JS file, such as: ClientLog.js, its code as follows: / ** * Write log at Web Client , use javascript * @author Felix liang * @email: lxfneer@163.com * / function Logger (FileName, logFile) {if (logFile = null!) this.logFileName = logFile; else this.logFileName = "c: // Clien_log.txt "; // Default log file this.prior = 0; // 0: All, 1: Debug, 2: Info, 3: Warn, 4: Error, 5: Fatal, 6: Offthis.FileName = filename; this.debug = writeDebug; this.info = writeInfo; this.warn = writeWarn; this.error = writeError; this.fatal = writeFatal; this.writeLogFuc = writeLog; this.isDebugEnabled = function () {return checkDebug (this.Prior , 1);} this.isinfoenabled = function () {Return CHECKDEBUG (this.Prior, 2);} this.iswarnenabled = function () {returnckdebug (this.Prior, 3);} this.iserrorenabled = function () {Return CHECKDEBUG (this.Prior, 4);} this.isfatalenabled = function () {returnckdebug (this.prior, 5);}
}
Function Checkdebug (DPRI, PRI) {IF (Pri> = DPRI) Return True; Else Return False;}
Function Writeebug (Info, EX) {if (! this.IndebugeNabled ()) Return; this.writelogfuc ("Debug", Info, EX);
Function WriteInfo (INFO, EX) {if (! this.Indebuginfo ()) Return; this.writelogfuc ("info", info, ex);}
Function WriteWarn (Info, EX) {if (! this.Indebugwarn ()) Return; this.writelogfuc ("Warn", Info, EX);
Function WriteError (Info, EX) {if (! this.iserrorenabled ()) Return; this.writelogfuc ("Error", Info, EX);
Function Writefatal (Info, EX) {if (! this.isfatalenabled ()) Return; this.writelogfuc ("Fatal", Info, EX);}
Function WriteLog (Prids, Info, EX) {
Try {IF (this.fso == null) this.fso = new activiXObject ("scripting.filesystemObject");} catch (ex2) {Alert (ex2);} if (! this.fso.fileexists (this.logfileename) ) {this.logfile = a; var a = this.fso.createtextFile (this.logfilename); a.close ();} var A = this.fso.opentextfile (this.logfilename, 8); var s = "" ; D = new date (); s = d.Getyear () "-"; s = (D.GETMONTH () 1) "-"; s = d.Getdate () "" VAR C = ":"; s = D.GETHOURS () C; s = d.getminutes () c; s = d.Getseconds () C; s = D.GETMILLISECONDS (); A .Writeline (S " " ") - [" (Info == NULL? "": Info) "]"); if (ex! = Null) a.writeline (" - " EX " ");
a.close ();
}
Function ErrorTrap (MSG, URL, LINE) {Glog = New Logger ("Globe"); if (Glog.iserrorenabled ()) Glog.Error ("URL:" URL "; line:" line "; msg:" msg); return true;
WINDOW.οNERRοR = ErrorTrap;