Compiled Script Logging?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Compiled Script Logging?

Post by Phil Pendlebury » Sun Jul 30, 2023 5:23 pm

I have found a few very old threads about this and would like to ask a quick question about logging from a compiled script.

I already understand that the log file can bet set like this:

Code: Select all

Let>LOGFILE=%SCRIPT_DIR%\support.log
And that log file writing can be turned on and off with this (1=on 0-off):

Code: Select all

Let>_WRITE_LOG_FILE=1
What I cannot get happening is the writing of the log file.

For example, I have an ini file which has a value.

Code: Select all

writelogfile=False
And the user can edit this and change it to:

Code: Select all

writelogfile=True
I then read this ini value to a variable, let us say %writesuplog%

What I am trying to do is this:

Code: Select all

IF>%writesuplog%=True
  Write the log file somehow.
ENDIF
I have been able to do this by making my own log messages and parameters, but I think it would be much easier to use the built in logging if only I can get it to work.

So, what will go in place of: "Write the log file somehow." in order to get the compiled application to log?

Thank you.
Phil Pendlebury - Linktree

User avatar
Grovkillen
Automation Wizard
Posts: 1024
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Compiled Script Logging?

Post by Grovkillen » Sun Jul 30, 2023 8:30 pm

Just a little suggestion:

Code: Select all

IF>writesuplog=True
  Write the log file somehow.
ENDIF
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Compiled Script Logging?

Post by Dorian (MJT support) » Sun Jul 30, 2023 9:35 pm

When compiling, put this in the "Include Parameters" box at the bottom :

Code: Select all

LOGFILE=%SCRIPT_DIR%\support.log
However, I am finding that let>_write_log_file=0 is not preventing the logfile being created, so I'll be looking in to that.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Compiled Script Logging?

Post by Phil Pendlebury » Mon Jul 31, 2023 4:49 am

Hi guys,

I am sorry but I fear you have both missed my point here. (My fault I am sure).

Code: Select all

IF>%writesuplog%=True
As code, works perfectly to execute what is inside it. I have been using this method for 15+ years, no issues.

I thought I had already mentioned that I have compiled with:

Code: Select all

LOGFILE=%SCRIPT_DIR%\support.log
So, no issues there either.

What I am looking for is the actual command that will initiate writing the log from a compiled script.

This part of my post:

Code: Select all

Write the log file somehow.
TLDR:

If I have set a variable that will tell the script it is Ok to write a log file. How do we actually tell the compiled script to start writing the log file? Can it only be done with command line?
Phil Pendlebury - Linktree

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Compiled Script Logging?

Post by Dorian (MJT support) » Mon Jul 31, 2023 8:48 am

Apologies for this being a little long-winded. It's my MO to always try and be as thorough as possible.

If you've already successfully logged compiled scripts then we're part way there.

The script needs a log file set, and that's something you're already familiar with.

A logfile will still be generated if we set _write_log_file to zero - it just won't log subsequent lines unless we set it to 1 again.

If I compile the following script (and make sure to specify the logfile) :

Code: Select all

// COMPILE_OPTS|D:\mondaylogINI.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylogINI.log|RUNTIMES=0|BMPS=1
let>_write_log_file=0
let>this=that
let>cat=dog
let>_write_log_file=1
let>bee=bird
let>water=wine
let>_write_log_file=0
let>day=night
let>dark=light
... the resulting logfile shows the lines after let>_write_log_file=0 are not logged :

Code: Select all

31/07/2023 09:19:30:406 - Started Macro : D:\mondaylog1.exe
31/07/2023 09:19:30:416 - START: 1: // COMPILE_OPTS|D:\mondaylog1.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylog1.log|RUNTIMES=0|BMPS=1
31/07/2023 09:19:30:426 -   END: 1: // COMPILE_OPTS|D:\mondaylog1.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylog1.log|RUNTIMES=0|BMPS=1
31/07/2023 09:19:30:436 - START: 2: let>_write_log_file=0
31/07/2023 09:19:30:446 -   END: 5: let>_write_log_file=1
31/07/2023 09:19:30:456 - START: 6: let>bee=bird
31/07/2023 09:19:30:466 -   END: 6: let>bee=bird
31/07/2023 09:19:30:476 - START: 7: let>water=wine
31/07/2023 09:19:30:486 -   END: 7: let>water=wine
31/07/2023 09:19:30:496 - START: 8: let>_write_log_file=0
31/07/2023 09:19:30:506 - Finished Macro : D:\mondaylog1.exe
Even if let>_write_log_file=0 was the first line of code, we'd still end up with a logfile which would look like this :

Code: Select all

31/07/2023 09:19:30:406 - Started Macro : D:\mondaylog1.exe
31/07/2023 09:19:30:416 - START: 1: // COMPILE_OPTS|D:\mondaylog1.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylog1.log|RUNTIMES=0|BMPS=1
31/07/2023 09:19:30:426 -   END: 1: // COMPILE_OPTS|D:\mondaylog1.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylog1.log|RUNTIMES=0|BMPS=1
31/07/2023 09:19:30:436 - START: 2: let>_write_log_file=0
31/07/2023 09:19:30:506 - Finished Macro : D:\mondaylog1.exe
So the logfile would still be generated.

With the above clarified, we can use an ini file to turn off logging from within the script :

My False ini file :

Code: Select all

[settings]
logging=False
My script :

Code: Select all

// COMPILE_OPTS|D:\mondaylogINI.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylogINI.log|RUNTIMES=0|BMPS=1
ReadIniFile>d:\myini.ini,settings,logging,writelogfile
If>writelogfile=False
let>_write_log_file=0
Endif

let>this=that
let>cat=dog
let>bee=bird
let>water=wine
let>day=night
let>dark=light
The logfile :

Code: Select all

31/07/2023 09:30:39:977 - Started Macro : D:\mondaylogINI.exe
31/07/2023 09:30:39:987 - START: 1: // COMPILE_OPTS|D:\mondaylogINI.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylogINI.log|RUNTIMES=0|BMPS=1
31/07/2023 09:30:39:997 -   END: 1: // COMPILE_OPTS|D:\mondaylogINI.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylogINI.log|RUNTIMES=0|BMPS=1
31/07/2023 09:30:40:027 - START: 14: ReadIniFile>d:\myini.ini,settings,logging,writelogfile
31/07/2023 09:30:40:037 -   END: 14: ReadIniFile>d:\myini.ini,settings,logging,writelogfile
31/07/2023 09:30:40:037 - START: 15: If>writelogfile=False
31/07/2023 09:30:40:047 -   END: 15: If>writelogfile=False
31/07/2023 09:30:40:057 - START: 16: let>_write_log_file=0
31/07/2023 09:30:40:067 - Finished Macro : D:\mondaylogINI.exe
My true ini file :

Code: Select all

[settings]
logging=True
Using the same script.

Code: Select all

31/07/2023 09:30:07:882 - Started Macro : D:\mondaylogINI.exe
31/07/2023 09:30:07:892 - START: 1: // COMPILE_OPTS|D:\mondaylogINI.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylogINI.log|RUNTIMES=0|BMPS=1
31/07/2023 09:30:07:892 -   END: 1: // COMPILE_OPTS|D:\mondaylogINI.exe||CONSOLE=0|INCLUDES=1|/LOGFILE=D:\mondaylogINI.log|RUNTIMES=0|BMPS=1
31/07/2023 09:30:07:922 - START: 14: ReadIniFile>d:\myini.ini,settings,logging,writelogfile
31/07/2023 09:30:07:932 -   END: 14: ReadIniFile>d:\myini.ini,settings,logging,writelogfile
31/07/2023 09:30:07:942 - START: 15: If>writelogfile=False
31/07/2023 09:30:07:952 -   END: 15: If>writelogfile=False
31/07/2023 09:30:07:962 - START: 19: let>this=that
31/07/2023 09:30:07:972 -   END: 19: let>this=that
31/07/2023 09:30:07:972 - START: 20: let>cat=dog
31/07/2023 09:30:07:982 -   END: 20: let>cat=dog
31/07/2023 09:30:07:992 - START: 21: let>bee=bird
31/07/2023 09:30:08:002 -   END: 21: let>bee=bird
31/07/2023 09:30:08:012 - START: 22: let>water=wine
31/07/2023 09:30:08:022 -   END: 22: let>water=wine
31/07/2023 09:30:08:032 - START: 23: let>day=night
31/07/2023 09:30:08:042 -   END: 23: let>day=night
31/07/2023 09:30:08:052 - START: 24: let>dark=light
31/07/2023 09:30:08:062 -   END: 24: let>dark=light
31/07/2023 09:30:08:082 - START: 37: 
31/07/2023 09:30:08:092 -   END: 37: 
31/07/2023 09:30:08:102 - Finished Macro : D:\mondaylogINI.exe
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1354
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Compiled Script Logging?

Post by Dorian (MJT support) » Mon Jul 31, 2023 8:53 am

Just after I hit submit it occurred to me that if you wanted to delete that logfile after running, you could put this at the end of your script :

Code: Select all

If>writelogfile=False
Deletefile>D:\mondaylogINI.log
Endif
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Compiled Script Logging?

Post by Phil Pendlebury » Mon Jul 31, 2023 10:24 am

Hi Dorian,
If you've already successfully logged compiled scripts then we're part way there.
No I haven't this is my entire question. :-) I cannot get the logfile to be created when running a compiled script.

Thanks for that. Unfortunately, this is all pretty much as I have it already. I have used ini files etc. many times so the issue is not there.

Even turning logging on and off is not the issue (at this point). So, for now, we can ignore the ini file and Let>_WRITE_LOG_FILE=1 options.

The issue is that the log file is just not being written from the compiled script.

I have tried:

Code: Select all

// COMPILE_OPTS|C:\Users\Phil\OneDrive\Downloads\MSFS Hours & Hobbs.exe|C:\Users\Phil\OneDrive\Pictures\Icons\Open Icons\ico\48x48\actions\document-open-recent-2.ico|CONSOLE=0|INCLUDES=1|/LOGFILE=c:\hhsupport.log|RUNTIMES=0|BMPS=0
and

Code: Select all

// COMPILE_OPTS|C:\Users\Phil\OneDrive\Downloads\MSFS Hours & Hobbs.exe|C:\Users\Phil\OneDrive\Pictures\Icons\Open Icons\ico\48x48\actions\document-open-recent-2.ico|CONSOLE=0|INCLUDES=1|/LOGFILE=%SCRIPT_DIR%\hhsupport.log|RUNTIMES=0|BMPS=0
etc. and have of course

Code: Select all

Let>_WRITE_LOG_FILE=1
within the script itself.

So, just ignoring any ini file options etc.

But when I compile the script and run the resulting exe file, no log file is created. I think I may be missing something.

This is why I asked, does the log file get created (when turned on with Let>_WRITE_LOG_FILE=1) when running a compiled script? Or is there more that needs doing? Does it have to be run with a command line switch?
Phil Pendlebury - Linktree

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Compiled Script Logging?

Post by Marcus Tettmar » Mon Jul 31, 2023 10:44 am

The first example specifies the file to be created in root C drive. That is unlikely to work unless you're running the exe as admin.

Second example uses a script variable. This won't be resolved in this instance.

Specify a location you can write to, or try without a path to write to same location as the exe (assuming it has permissions to do that which is likely NOT the case if installed in program files). e.g. /LOGFILE=mylog.txt
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Compiled Script Logging?

Post by Phil Pendlebury » Mon Jul 31, 2023 10:49 am

Thank you, Marcus. :-) Indeed, setting compile options to

/LOGFILE=C:\Users\Phil\Desktop\support.log

made a log for me :-) Great stuff, so I know it works now and why it was not being written. I did search a lot and could find no clear indication that the settings work from compiled scripts, so this is great. I will now be able to finish off the coding.
Phil Pendlebury - Linktree

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Compiled Script Logging?

Post by Phil Pendlebury » Mon Jul 31, 2023 11:11 am

Quick question:

Do any of the system vars get expanded when used in this option? i.e. %AppData%

I am guessing not... (I am struggling to find a generic place to write the log file to on a user's system, without running as Admin)

And while we are it, I find that even if I write

Code: Select all

Let>_WRITE_LOG_FILE=0
just before script exit, I still get the log file saying "31/07/2023 16:19:38:104 - Finished Macro"
Phil Pendlebury - Linktree

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

Re: Compiled Script Logging?

Post by JRL » Mon Jul 31, 2023 2:42 pm

(I am struggling to find a generic place to write the log file to on a user's system, without running as Admin)
No guaranties. Internal to our domain, using C:\ProgramData\Folder_I_Create works for me. Caveate being most users can't see the ProgramData folder so if you want them to see the file you either need to explain how to get there or script a viewer for the file.

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Compiled Script Logging?

Post by Phil Pendlebury » Mon Jul 31, 2023 5:16 pm

Thanks JRL. No need for them to see it. I move it and zip it. And for this I can use system vars etc. :-)
Phil Pendlebury - Linktree

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