Added logging

This commit is contained in:
Alex Berry 2020-03-04 20:46:01 +00:00
parent 1c4e395b0f
commit 4af48d5341
2 changed files with 26 additions and 4 deletions

View File

@ -31,3 +31,13 @@ To override the number of cores used to compile, set the Cores param when callin
```powershell ```powershell
.\compile.ps1 -Cores 2 .\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.

View File

@ -1,8 +1,19 @@
# Default params, $Cores must be set to 0 to automatically detect core count. # Default params, $Cores must be set to 0 to automatically detect core count.
Param( 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 param is set to 0, detect how many cores this machine has, else use $Cores
if ($Cores-ne 0) { if ($Cores-ne 0) {
Write-Host "Overriding core count with $Cores." Write-Host "Overriding core count with $Cores."
@ -16,9 +27,6 @@ else {
# Generate a list of files to process # Generate a list of files to process
$files = (ls *.pwn).Name $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. # 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 = { $Block = {
Param([string] $file, [string] $workdir) Param([string] $file, [string] $workdir)
@ -48,3 +56,7 @@ foreach($job in Get-Job){
# Remove all jobs created. # Remove all jobs created.
Get-Job | Remove-Job Get-Job | Remove-Job
if ($Log) {
Stop-Transcript
}