I need to instrument a series of .wsf and .vbs files with debug statements; before I go off and roll my own, does something like log4j exist for WSF/VBScript?
Not comparable to log4j, but something you could use to begin with:
Reusable Logging in VBScript - LogToFile.vbs
Anywhere you'd like to log a message within the script you'd simply add LogToFile "Your Message" to log the relevant information.
With this script you can log the date and time you began the script, the date and time of any particular events, and generate unique filenames if you want to schedule script run times. It's also simple to turn off logging without editing the entire logging section out.
If you want to write to the event log, you could do it using a WshShell object. It provides the LogEvent method for logging events to the Application event log.
The LogEvent method enables you to write to the event log from within your scripts. LogEvent has two required parameters. The first parameter of the LogEvent method is an integer that specifies the type of event you would like your script to log.
Set objShell = WScript.CreateObject("Wscript.Shell")
objShell.LogEvent 0,"Test Success Event"
objShell.LogEvent 1,"Test Error Event"
objShell.LogEvent 2,"Test Warning Event"
objShell.LogEvent 4, "Test Information Event"
objShell.LogEvent 8, "Test Success Audit Event"
objShell.LogEvent 16, "Test Failure Audit Event"
See here on the Microsoft TechNet site.
I suspect you may be able to use Log4net via COM. This is .net version of log4J and I highly recommend it as a logging framework. There is some info here
Since my main program is a Windows Scripting File (.wsf) script, I can include and use code from other scripting languages.
I found the Log4js: JavaScript logging framework, modeled after Log4j, which works very nicely for me. I had to add my own Appender for logging to stderr
and stdout
, but that was much easier than creating my own logging framework from scratch.
UPDATE: 2/13/2009:
The Log4js: JavaScript logging framework I first tried turned out to be a bit of a resource hog. I found another JavaScript Log4js implementation at http://log4js.sourceforge.net/ that is much more stable and efficient.