63 lines
2.0 KiB
PowerShell
63 lines
2.0 KiB
PowerShell
|
function Get-WebTestLogPath {
|
|||
|
<#
|
|||
|
.SYNOPSIS
|
|||
|
Get the web test log path for logging data mid-run so we can track what happens on disk during runtime testing.
|
|||
|
This function is intended to be used in ancillary test logging.
|
|||
|
|
|||
|
.DESCRIPTION
|
|||
|
The impetus for this change is that some things were breaking unexpectedly during testing and crashing the entire host.
|
|||
|
We needed a way to track where it was crashing the host mid-process. Hence this function and ..
|
|||
|
Write-* "message"
|
|||
|
becomes
|
|||
|
"message" | Tee-Object -Append -Path $thisPath | Write-*
|
|||
|
|
|||
|
.PARAMETER BankUrl
|
|||
|
[Required] [string] The bank url to log for
|
|||
|
|
|||
|
.PARAMETER Widget
|
|||
|
[Optional] [string] The widget to log for.
|
|||
|
#>
|
|||
|
[CmdletBinding()]
|
|||
|
param(
|
|||
|
[Parameter(Mandatory = $true)]
|
|||
|
[Alias("LogName")]
|
|||
|
[string]$BankUrl,
|
|||
|
|
|||
|
[Parameter(Mandatory = $false)]
|
|||
|
[string]$Widget
|
|||
|
)
|
|||
|
|
|||
|
$logFilePath = (Join-Path (Get-OrbLogsPath) WebTests)
|
|||
|
if (!(Test-Path $logFilePath)) {
|
|||
|
New-Item -ItemType Directory -Path $logFilePath -Force
|
|||
|
}
|
|||
|
|
|||
|
$logUrlFilename = $BankUrl
|
|||
|
if ($BankUrl.ToLower().StartsWith("http")) {
|
|||
|
$uri = [System.Uri]::new($BankUrl)
|
|||
|
$logUrlFilename = $uri.DnsSafeHost
|
|||
|
|
|||
|
# If the widget wasn't passed in
|
|||
|
if ([string]::IsNullOrWhiteSpace($Widget)) {
|
|||
|
# and the url had a path
|
|||
|
$potentialWidget = $uri.LocalPath.Split('/')[1]
|
|||
|
if (![string]::IsNullOrWhiteSpace($potentialWidget)) {
|
|||
|
# grab the first part of that path as the widget name
|
|||
|
$Widget = $potentialWidget
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
$baseLogUrlFilename = $logUrlFilename
|
|||
|
if (![string]::IsNullOrWhiteSpace($Widget)) {
|
|||
|
$logUrlFilename = "$logUrlFilename.$Widget"
|
|||
|
}
|
|||
|
|
|||
|
$finalLogFilePath = (Join-Path $logFilePath "$logUrlFilename.log")
|
|||
|
|
|||
|
if (!(Test-Path $finalLogFilePath)) {
|
|||
|
$finalLogFilePath = (Join-Path $logFilePath "$baseLogUrlFilename.log")
|
|||
|
}
|
|||
|
|
|||
|
return $finalLogFilePath
|
|||
|
}
|