Toggle Script Logging On and Off

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
JRL
Automation Wizard
Posts: 3497
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Toggle Script Logging On and Off

Post by JRL » Tue Feb 07, 2017 10:37 pm

I have a 6000 line script that runs for as long as you let it run. It runs correctly until it doesn't. Setting up logging is helpful but the script may run for a long time before there is a failure. Plus as the log file gets into the millions of lines the script runs slower and slower.

There is a variable to control logging, _WRITE_LOG_FILE, that can be set to 1 or 0 in order to control whether logging is on or off, and I use that variable often. In this case though the resulting log file is so large because the same loop is logged over and over, that I was not finding helpful data.

Last night it occurred to me. I need a way to manually toggle logging on and off. The following script does that. The first script is a sample script that will demonstrate how this works. The second script is the bare minimum lines needed to be placed at the start of a script to have the ability to toggle logging on and off using the WinKey + F4 key combination.



Code: Select all

//To turn on logging at the beginning of your
//script remark or remove the following line.
Let>_WRITE_LOG_FILE=0

//Set this variable flag to 0 if you are starting
//with logging off or to 1 if you are starting
//with logging on
Let>WriteLogFlag=0


//Key press to toggle logging. In this case WinKey+F4
//VK115=F4
//Modifier 8=winkey
OnEvent>Key_Down,VK115,8,ResetWriteLog

//Key press to end the script.  WinKey+Esc
//VK27=Esc
//Modifier 8=winkey
OnEvent>Key_Down,VK27,8,Quit


SRT>ResetWriteLog
  If>WriteLogFlag=1
    Let>WriteLogFlag=0
    SetControlText>Macro Scheduler Message,TMemo,1,logging is off
  Else
    Let>WriteLogFlag=1
    SetControlText>Macro Scheduler Message,TMemo,1,logging is on
  EndIf
  Wait>1
  //CloseWindow>Macro Scheduler Message
  Let>_WRITE_LOG_FILE=%WriteLogFlag%
END>ResetWriteLog

SRT>Quit
  Exit>0
END>Quit

Let>kk=0

//Open a message box if you want to see the messages.
Message>
Label>Loop
  ADD>kk,1
  Wait>0.01
  SetControlText>Macro Scheduler Message,TMemo,1,%kk%
Goto>Loop


Code: Select all

Let>_WRITE_LOG_FILE=0
Let>WriteLogFlag=0
OnEvent>Key_Down,VK115,8,ResetWriteLog

SRT>ResetWriteLog
  If>WriteLogFlag=1
    Let>WriteLogFlag=0
  Else
    Let>WriteLogFlag=1
  EndIf
  Let>_WRITE_LOG_FILE=%WriteLogFlag%
END>ResetWriteLog

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts