using a processing/debug log

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Bernard
Posts: 351
Joined: Sat Apr 08, 2006 10:14 pm

using a processing/debug log

Post by Bernard » 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.

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
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?

marielle
Livecode Opensource Backer
Livecode Opensource Backer

Post by marielle » Thu Jan 18, 2007 1:32 pm

:D

Post Reply