When does FFS write the log file?

Discuss new features and functions
Posts: 12
Joined: 18 May 2022

ladarrius

I have a FFS batch file with an on-complete command to copy the most recent file from the default log folder
FOR /F "delims=" %f IN ('DIR "%AppData%\FreeFileSync\Logs\*.log" /B /O:-D /S') DO COPY /V /Y "%f" "C:\Users\me\Desktop" & EXIT
Recently (maybe in the latest few versions) I noticed that this copies the penultimate log file, not the one that was just completed. Adding a wait of a second or 2 before copying does not help.

This leads me to suspect that FFS is writing the log file after the on-completion command finishes. Can anyone confirm if this is correct?

(I can just change the log path for the batch but i would like to have it in the default log location with a copy created elsewhere)

Thanks!
User avatar
Posts: 3641
Joined: 11 Jun 2019

xCSxXenon

For troubleshooting, what if you change the on-completion command to wait ~30 seconds before the exit command? Then you can watch the sync finish and check the log folder. If the log file doesn't show up until those 30 seconds pass, then you'll know if the log is created before or after the command
User avatar
Site Admin
Posts: 7058
Joined: 9 Dec 2007

Zenju

The "on completion" command conceptually belongs to the sync job, so its exit code and potential console output are logged. This on the other hand means, it has to run *before* the log file is saved.

(I can just change the log path for the batch but i would like to have it in the default log location with a copy created elsewhere) ladarrius, 13 Jun 2022, 19:34
This use case is supposed to be solved by overriding the log folder path at sync config level. I'm wondering if there is potential for design improvement here, or if your scenario is just special.
Posts: 12
Joined: 18 May 2022

ladarrius

thanks for the comments guys
For troubleshooting, what if you change the on-completion command to wait ~30 seconds before the exit command? Then you can watch the sync finish and check the log folder. If the log file doesn't show up until those 30 seconds pass, then you'll know if the log is created before or after the command xCSxXenon, 13 Jun 2022, 20:46
so, adding a longer wait made it apparent that it's not actually waiting at all
TIMEOUT 30 /NOBREAK & FOR /F "delims=" %f IN ('DIR "%AppData%\FreeFileSync\Logs\*.log" /B /O:-D /S') DO COPY /V /Y "%f" "C:\Users\me\Desktop" & EXIT
this works fine in cmd (waits, then copies, then exits), but as an FFS_batch on-completion command it doesn't actually wait the specified amount of time

This use case is supposed to be solved by overriding the log folder path at sync config level. Zenju, 18 Jun 2022, 19:07
would you mind elaborating on this? which feature are you referring to I'm not too familiar with that. wouldn't overriding the log path just create one log at the custom location, not multiple copies of the same log? or am i mistaken about this?
I'm wondering if there is potential for design improvement here, or if your scenario is just special. Zenju, 18 Jun 2022, 19:07
if i were to guess i would say my use case is probably the odd one out. at the basics, I'm looking for multiple copies of the same log file to be made in different locations. is this something with a sufficiently generalized use? of course it would be great for me if ffs added support for that natively :p
Posts: 12
Joined: 18 May 2022

ladarrius

in case anyone else might find this useful, this workaround should work:

put the main script into a batch file and have ffs' on-completion command be
start "" "path\to\bat"
"start" by default does not wait for the spawned process to finish before exiting which will allow ffs to wrap up. can put a brief timeout at the start of the batch script to make sure it executes after ffs is done.

this should be a workable solution for this edge case and requires no changes to how ffs handles the exit command.