Tips: Quickly insert _Log_Group() to trace function call
Not a real stack trace but it would be handy to log both function name and parameter passed, but its painfull task to insert them manually in each Function entry.
We can use
Regular Expression search and replace to make the process semi-automatic
Requirement:Notepad++ which support "matches newline" option (at the right side of "Regular exp
ression"
Search mode option)
I'm using v6.1.2
Set ConsoleLog to log into file only, as console output will be too fast to read
#include "ConsoleLog.au3"
$_CL_Log_Mode = 3
$_CL_Log_FileMode = @ScriptDir & "\" & @ScriptName & "-trace.txt"
_ConsoleLog_Start()
We use this function declaration for illustration:
Func SomeFunction($param1, $param2 , $param3=True,$param4 =0)
To open the search and replace dialog press
Ctrl+H, all the steps below will use
Regular Expression in Search mode
Step #1: Insert _Log_Group
- Select Regular Expression mode and turn "matches newline" ON
- Find what: ^(Func\s+([^ \(]+)\(([^\)]*)\)[^\n]*\n)
Replace with: \1_Log_Group\("\2 \(" & \3 & "\)"\)\n - Click "Replace All" or Alt+A ONCE
the result should be (
green = the changes):
Func SomeFunction($param1, $param2 , $param3=True,$param4 =0)
_Log_Group("SomeFunction (" & $param1, $param2 , $param3=True,$param4 =0 & ")")Step #2: Strip out default parameter values
- turn "matches newline" OFF
- Find what: ^(_Log_Group[^=\n]*)=[^,&\)]+([^\n]*)
Replace with: \1\2 - Repeately pressing Alt+A until no matches found
the result should be:
Func SomeFunction($param1, $param2 , $param3=True,$param4 =0)
_Log_Group("SomeFunction (" & $param1, $param2 ,
$param3,$param4 & ")")
Step #3: Reformat parameters
- Find what: ^(_Log_Group[^,\n]*),\s*
Replace with: \1 & "; " & - Repeately pressing Alt+A until no matches found
the result should be:
Func SomeFunction($param1, $param2 , $param3=True,$param4 =0)
_Log_Group("SomeFunction (" & $param1
& "; " & $param2
& "; " & $param3
& "; " & $param4 & ")")
Step #4: Reformat empty parameter
- Find what: &\s*&
Replace with: & " " & - Repeately pressing Alt+A until no matches found
Thats it, run your script. The trace file would be in the same directory with your script.
If the script have error before, the trace will stop on the function where the error happened,
If not you can make break points like MsgBox (0, "", "Breakpoint"), run and then (re)open the trace file in notepad each time the dialog box popped up (notepad++ can update itself when the trace file changed)
NOTE: You can assign step 2 - 4 as macro, which is convenient. But carefull with step 1, it can make _Log_Group doubled if executed more than once.
When you finish debugging, you can remove them all at once:
Step #5: Remove all _Log_Group() under Function declaration
- turn "matches newline" ON
- Find what: ^(Func\s+[^ \(]+\([^\n]*\n)_Log_Group[^\n]*\n
Replace with: \1
Hope it helps, Happy debugging