eimhym Posted May 30, 2012 Posted May 30, 2012 I need the tray menu functionality but starring at the console somewhat relaxing (if not hypnotic) so...How to use:=========; Include statement #include<Constants.au3> ; Features $_CL_Log_Mode = 2 ; 0: Disabled, 1: Console only, 2: Both Console and File logging, 3: Log to file only ; Console settings $_CL_Console_Closed = 0 ; When someone click the "x" thingy at top right corner of the console 0: Don't kill script (see notes in source code), 1: Kill script ; File settings $_CL_Log_FileMode = 0 ; How the log file be named 0: Use script name, 1: Autogenerated log filename, String: Use as log filename (full-pathname) $_CL_Log_FileExt = ".log" ; Log file extension ; invoke to start logging _ConsoleLog_Start ()If Console is enabled_Log($msg) Will write $msg to console_Log_Group($msg) Will change the console title. When console is minimized or behind other window, we can still informed by console title at the taskbar._Log_Hide() Hide console window, logging still continue_Log_Show() Show the console windowIf File Logging is enabled_Log($msg) Will write $msg to file, preceeded by timestamp_Log_Group($msg) Will write $msg to file, without timestampUsage ExampleUncomment code at the bottom of source file and runFeature Request(reserved)What is notMulti log level I'd (or someone) rather start ConsoleLogEx ... laterConsoleLog.au3
eimhym Posted May 31, 2012 Author Posted May 31, 2012 Tips: Quickly insert _Log_Group() to trace function callNot 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-automaticRequirement:Notepad++ which support "matches newline" option (at the right side of "Regular expression" Search mode option)I'm using v6.1.2Set 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 modeStep #1: Insert _Log_GroupSelect Regular Expression mode and turn "matches newline" ONFind what: ^(Func\s+([^ \(]+)\(([^\)]*)\)[^\n]*\n) Replace with: \1_Log_Group\("\2 \(" & \3 & "\)"\)\nClick "Replace All" or Alt+A ONCEthe 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 valuesturn "matches newline" OFFFind what: ^(_Log_Group[^=\n]*)=[^,&\)]+([^\n]*) Replace with: \1\2Repeately pressing Alt+A until no matches foundthe result should be:Func SomeFunction($param1, $param2 , $param3=True,$param4 =0)_Log_Group("SomeFunction (" & $param1, $param2 , $param3,$param4 & ")")Step #3: Reformat parametersFind what: ^(_Log_Group[^,\n]*),\s* Replace with: \1 & "; " &Repeately pressing Alt+A until no matches foundthe result should be:Func SomeFunction($param1, $param2 , $param3=True,$param4 =0)_Log_Group("SomeFunction (" & $param1 & "; " & $param2 & "; " & $param3 & "; " & $param4 & ")")Step #4: Reformat empty parameterFind what: &\s*& Replace with: & " " &Repeately pressing Alt+A until no matches foundThats 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 declarationturn "matches newline" ONFind what: ^(Func\s+[^ \(]+\([^\n]*\n)_Log_Group[^\n]*\n Replace with: \1Hope it helps, Happy debugging
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now