Jump to content
Sign in to follow this  
eimhym

GUI Mode simple Console+File Logging

Recommended Posts

eimhym

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 window

If File Logging is enabled
  • _Log($msg)

    Will write $msg to file, preceeded by timestamp

  • _Log_Group($msg)

    Will write $msg to file, without timestamp

Usage Example

Uncomment code at the bottom of source file and run

Feature Request

  • (reserved)
What is not
  • Multi log level

    I'd (or someone) rather start ConsoleLogEx ... later

ConsoleLog.au3

Share this post


Link to post
Share on other sites
eimhym

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 expression" 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 ;)

Share this post


Link to post
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
Sign in to follow this  

×