A debug logging class for your Excel applications
I first used logging as a tool to decipher the data being passed around my spreadsheets whilst they were in use. I suffered a spate of complaints that they weren't working as they should but given the situation I was told about, it seemed impossible for them to fail. Logging allowed me to understand the flow of data without being sat in front of the machine all the time.
I had played with logging to an invisible sheet but this caused unreasonable file bloat which I was unhappy about.
Since working with applications connected to databases, I have used logging more and more, particularly when they are apps I've written (mostly in VB6).
This class provides a logging object that you can create and destroy as you like, the properties it has are:
CurrentProcedure
LogFile
LogLevel
MaxFileIterations
MaxFileSize
The methods are:
BeginLogging
StopLogging
IUPrint
If you create a global clsLogger object, in each procedure you can pass .CurrentProcedure the name of the procedure as a string. Anytime you want to log some data, use the IUPrint method to write out to the file. The logfile is kept open for the duration of your application to save time, the WriteFile API is used for this purpose also.
The IUPrint method takes the LogLevel of the message, the message itself and a parameter array of other data you'd like to write to the file. The levels work like this:
clslogger.LogLevel is set at 3, an IUPrint is processed passing a level of 5, IUPrint will not write it out to the file
clslogger.LogLevel is set at 3, an IUPrint is processed passing a level of 2, IUPrint will write it out to the file.
This way, you can up or down the level of logging to conserve log file size.
LogFile is the name of the file to be logged to. It will have a .Log extension, unless you make use of the File Iteration feature. File Iteration allows you to save to files until they reach a certain size(MaxFileSize), it will then change the extension to 002, 003 etc., until MaxFileIterations is met, then it will revert back to 001 again.
LogFile is the name of the initial logfile, without an extension.
The properties can be set in the registry, a database or perhaps more easily, a worksheet.
24 Nov 2005 - Fixed a bug that caused a Logging Failed message if code was stopped and restarted within the VBE
I have also created a VB6 version of this code