Writing Jscript is a tough task, there were no errors if the data is well structured, but somtimes i wish to log all those information & exception in some place to review/analyse. Yes we can log all them in browser event log, but that is temprorary and will be all gone when the window is closed. Still there is something that you can do with Windows Event Logger. Here is a small script that uses activeXObject to write the log to eventviewer. Later you can view the log by running "eventvwer" in the cmd prompt.
And this is how you can call it:
Note: Due to inconsistent ActiveX use, it works only with InternetExplorer browser family :(
..keep coding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Jscript - event logger */ | |
// Creates a Eventlog object | |
function EvntLog(){ | |
this.about = "This will log all the messages to system event log on a IE browser"; | |
} | |
// adds functions to it | |
EvntLog.prototype = { | |
Error:function(ErrorMsg){ | |
var WshShell = new ActiveXObject("WScript.shell"); | |
WshShell.LogEvent(1,Error); | |
}, | |
Success:function(SuccessMessage){ | |
var WshShell = new ActiveXObject("WScript.shell"); | |
WshShell.LogEvent(0,Message); | |
}, | |
Warn:function(WarningMessage){ | |
var WshShell = new ActiveXObject("WScript.shell"); | |
WshShell.LogEvent(2,Message); | |
}, | |
Info:function(InformationMessage){ | |
var WshShell = new ActiveXObject("WScript.shell"); | |
WshShell.LogEvent(4,Information); | |
}, | |
AuditSuccess:function(AuditSuccessMessage){ | |
var WshShell = new ActiveXObject("WScript.shell"); | |
WshShell.LogEvent(8,Message); | |
}, | |
AuditFailure:function(AuditFailureMessage){ | |
var WshShell = new ActiveXObject("WScript.shell"); | |
WshShell.LogEvent(16,Message); | |
} | |
} |
And this is how you can call it:
// Calling the log to write error EvntLog.Err("error in script");
Note: Due to inconsistent ActiveX use, it works only with InternetExplorer browser family :(
..keep coding