loganips
Posts: 22
Joined: Wed Jun 17, 2015 6:26 pm

Appending timestamp to the log file.

Fri Oct 12, 2018 8:39 pm

Hello,
We are currently using the Bootstrapper Options MSI Command line to create a verbose log file at a custom location eg. /L*V "[WindowsVolume]Temp\Installer.log". Is there any way that we can append a timestamp to the end of this filename so the filename would be something like Installer-2018-10-12 15-23-00.log?

Any input is appreciated.

Thanks,
Logan

Catalin
Posts: 6536
Joined: Wed Jun 13, 2018 7:49 am

Re: Appending timestamp to the log file.

Mon Oct 15, 2018 2:14 pm

Hello Logan,

I am afraid that what you want to achieve is not possible.

The "MSI command line" field is of PseudoFormatted type, which means that the references are replaced with the value of the respective properties at build time. The Date and Time properties are set when the data is extracted.

Also, please keep in mind that data such as the date and the time when the log was created are logged within the file, on the first line.

Kind regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

loganips
Posts: 22
Joined: Wed Jun 17, 2015 6:26 pm

Re: Appending timestamp to the log file.

Mon Oct 15, 2018 4:00 pm

Thanks Catalin,

I figured this would be the case, and I am aware that the date and time is shown in the log file. The reason we wanted to put it in the filename is that we have had a couple instances of installs encountering errors, and then when the installer is run again it wipes out the log file from the failed installation.

It would be useful to have a way to preserve the original log file but if that is not possible I understand.

Thanks again for the information,
Logan

Catalin
Posts: 6536
Joined: Wed Jun 13, 2018 7:49 am

Re: Appending timestamp to the log file.

Tue Oct 16, 2018 10:40 am

Hello Logan,

First of all, thank you for the explanation. Now I understand better your scenario and indeed, the way you wanted to proceed is the best way. By dynamically changing the log name, it would not be overwritten when running the installer again (but instead would create a new log everytime the setup is run).

However, after I have investigated this a bit more, I have come up with the main reason why that is not working and also with a workaround. First of all, the reason why that does not work is because the date and the time format contains characters that are not supported by Windows OS file name format (e.g. ":", "/").

The workaround to this is as follows: We will create a custom action based on a PowerShell script which will get your log file, copy it on the desktop and then rename it using timestamps.

In order to achieve those said above, please proceed as it follows:

-Go to "Custom Actions" page

-Add a "Run PowerShell inline script" custom action without sequence by pressing the "Add custom action without sequence" button which is placed to the right side of the custom action name. We will add this without sequence, so we can trigger it from a dialog control (button) - that being the "Finish" button from our "ExitDlg" dialog.

-Under the "Your code goes here." comment, please insert the following script:

Code: Select all

tempFolder = $env:TEMP
$userProf = $env:USERPROFILE
$date = (get-date -format d) -replace("/")
$time = (Get-Date -Format t) -replace(":")
Copy-Item "$tempFolder\Installer.log" -Destination "$userProf\Desktop"
$newFileName = "$date"+"_"+"$time"+"Installer.log"
Rename-Item "$userProf\Desktop\Installer.log" -NewName $newFileName
-Now please go to "Dialogs" page, select the "ExitDlg" dialog and click on the "Finish" button --> under "Published Events" click on the "New..." button to add an event with the following arguments:

-Event: Execute custom action
-Argument: PowerShellScriptInline
-Condition: leave unchanged


Hope this helps.

All the best,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

loganips
Posts: 22
Joined: Wed Jun 17, 2015 6:26 pm

Re: Appending timestamp to the log file.

Tue Oct 16, 2018 3:31 pm

Hello,

Thanks for the information! I never would have thought to use the exit dialog to achieve this goal. This solved our problem and will allow us to retain our log files.

Thanks again,
Logan

Catalin
Posts: 6536
Joined: Wed Jun 13, 2018 7:49 am

Re: Appending timestamp to the log file.

Wed Oct 17, 2018 8:19 am

You're always welcome, Logan.

I am really glad you got this working.

Kind regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”