From 4af48d5341b8b78fcff2b0d435ddf83df7d90072 Mon Sep 17 00:00:00 2001 From: Alex Berry Date: Wed, 4 Mar 2020 20:46:01 +0000 Subject: [PATCH] Added logging --- README.md | 10 ++++++++++ compile.ps1 | 20 ++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 72b282f..a140253 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,13 @@ To override the number of cores used to compile, set the Cores param when callin ```powershell .\compile.ps1 -Cores 2 ``` + +### Enable Logging +To have the script log to ```compile.txt``` in the maps directory, set the ```$Logs``` param to ```$True```: +```powershell +.\compile.ps1 -Logs $True +``` +Or update the default Parameter on line 4 to ```$True``` + +### Performance Note +When logging is enabled, although the files compile just as fast, the script takes longer to finish as it writes the file. All you need to know is that as soon as the red text starts rushing past, all the files have finished compiling. diff --git a/compile.ps1 b/compile.ps1 index 83b27c6..394d95f 100644 --- a/compile.ps1 +++ b/compile.ps1 @@ -1,8 +1,19 @@ # Default params, $Cores must be set to 0 to automatically detect core count. Param( - [Int]$Cores = 0 + [Int]$Cores = 0, + [Bool]$Log = $False ) +# Set the working directory to pass in to the background job +$workdir = (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent) + +# Start logging + +if ($Log) { + Start-Transcript -Path $workdir\compile.txt +} + + # If $Cores param is set to 0, detect how many cores this machine has, else use $Cores if ($Cores-ne 0) { Write-Host "Overriding core count with $Cores." @@ -16,9 +27,6 @@ else { # Generate a list of files to process $files = (ls *.pwn).Name -# Set the working directory to pass in to the background job -$workdir = (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent) - # Define the script block, used by start-job when initiating the background job. This block defines the command that will be run, along with it's parameters. $Block = { Param([string] $file, [string] $workdir) @@ -48,3 +56,7 @@ foreach($job in Get-Job){ # Remove all jobs created. Get-Job | Remove-Job + +if ($Log) { + Stop-Transcript +}