using a processing/debug log
Posted: Thu Jan 18, 2007 11:19 am
I build in calls to a debugging 'transcribe' handler that also serves to comment on the processing. Basically the transcribe handler is invoked liberally throughout the code, and in each invokation it can tell me which handler it is in, what it is doing at that point, and the values of relevant variables there.
Statements are logged conditionally if they pass the logging threshold. Timings can also be included or not. And there are optional separators that can be used to clearly delineate certain pieces of processing in the log.
I often find this is more useful than inspecting values in the debugger or using trace. Also, it can optionally be switched on in standalones by setting a custom property in the main stack.
Do others use similar techniques?
Statements are logged conditionally if they pass the logging threshold. Timings can also be included or not. And there are optional separators that can be used to clearly delineate certain pieces of processing in the log.
Code: Select all
on transcribe pDebugLoggingLevel pText pLogItemSeparator
put getMainStackName(the long name of the target) into tMainStack
if the uIsDebugOn of tMainStack then
put the uDebugLoggingLevel of tMainStack into tDebugThreshold
if pDebugLoggingLevel <= tDebugThreshold then -- pText should be logged
put empty into tLogLevel
put empty into tLapsedMS
if (the uLogDisplaysDuration of tMainStack) then -- calculate time since last statement added to log
put the uTimeOfLastLogEntryAsMS of tMainStack into tTimeOfLastLogEntry
put the millisecs into tNowMS
if tTimeOfLastLogEntry is empty then -- first time we have logged anything in this session
put tNowMS into tTimeOfLastLogEntry
end if
set the uTimeOfLastLogEntryAsMS of tMainStack to tNowMS
put tab & (tNowMS - tTimeOfLastLogEntry) && "ms" into tLapsedMS
end if
if the uLogDisplaysLoggingLevel of tMainStack is true then
put tab & pDebugLoggingLevel into tLogLevel
end if
put the uDebugLog of this stack into tLog
put tLogLevel & tLapsedMS & tab & pText && pLogItemSeparator & return after tLog
set the uDebugLog of this stack to tLog
end if
end if
end transcribe
Do others use similar techniques?