Jump to content

DebugLogText


Dan_555
 Share

Recommended Posts

Hi, 

this script could be used for debugging purposes.

If you have a function which, on rare occasions, causes an error, or freezes the script, but you are unable to identify the cause yet, then use this as a debugging output.

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         Dan_555

 Script Function:   Displaying important debugging text in a listbox

                    The maximum item numer in this listbox can be limited
                    so that the old items get deleted, when a new entry comes in                    
#ce ----------------------------------------------------------------------------

#include <GuiListBox.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>

Global $debugCombomaxlines = 8, $debug_on = 1 ;Debug_on: enables-disables the debugging window. $debugCombomaxlines: How many items shall be always present in the list box.


If $debug_on = 1 Then
    Global $debug = GUICreate("DebugLog", 320, 170, Default, Default, BitOR($WS_THICKFRAME, $WS_MINIMIZEBOX))
    Global $debug_label = GUICtrlCreateLabel("Debug Last Active = 00:00:00", 4, 4)
    Global $idDEBUGListBox = GUICtrlCreateList("", 2, 22, 300, 130)
    GUISetState(@SW_SHOW, $debug)
EndIf


Func DebugLogText($txt)
    If $debug_on = 1 Then
        _GUICtrlListBox_BeginUpdate($idDEBUGListBox)
        If _GUICtrlListBox_GetCount($idDEBUGListBox) >= $debugCombomaxlines Then _GUICtrlListBox_DeleteString($idDEBUGListBox, $debugCombomaxlines)
        _GUICtrlListBox_InsertString($idDEBUGListBox, @HOUR & ":" & @MIN & ":" & @SEC & " - " & $txt, 0)
        _GUICtrlListBox_EndUpdate($idDEBUGListBox)
    EndIf
EndFunc   ;==>DebugLogText


;example code

Local $hTimeI = TimerInit()

While GUIGetMsg() <> $GUI_EVENT_CLOSE

    If $debug_on = 1 Then GUICtrlSetData($debug_label, "Loop Last Active =" & @HOUR & ":" & @MIN & ":" & @SEC) ;Debugging only

    If TimerDiff($hTimeI) > 1000 Then
        DebugLogText("Action #" & Int(Random(0, 100)) & " occured")
        $hTimeI = TimerInit()
    EndIf

WEnd

 

The listbox displays a rolling text, old entries (at the bottom) will be deleted, once the maximum defined number of lines is reached.

The debugging text includes a time stamp. 

 

This function i have used to debug the UniversalScreenMate app. On a very rare occasion, sometime after few days of Hilbernating the PC, the Screenmate would walk endlessly in one direction.

And to identify which function, or which part of the function causes this, i wrote the above script, and placed many DebugLogText  lines, with meaningful identifiers, and finally i could fix it. 

 

To disable the debugging output, all you need to do is to set the $debug_on variable to 0. 

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...