From 00a2fdf625f194ac0b9d15c340cb80344f94e263 Mon Sep 17 00:00:00 2001 From: Raymond Piller Date: Thu, 12 Jan 2023 23:22:26 -0600 Subject: [PATCH] Converted to environment variables --- ...ionHeader.ps1 => Get-InvocationHeader.ps1} | 6 +- PSWriteLog/Private/Write-Log.ps1 | 75 ++++++++--------- PSWriteLog/Public/Write-Debug.ps1 | 17 ++-- PSWriteLog/Public/Write-Error.ps1 | 11 +-- PSWriteLog/Public/Write-Host.ps1 | 11 +-- PSWriteLog/Public/Write-Information.ps1 | 13 ++- PSWriteLog/Public/Write-Output.ps1 | 7 +- PSWriteLog/Public/Write-Progress.ps1 | 80 +++++++++---------- PSWriteLog/Public/Write-Verbose.ps1 | 11 +-- PSWriteLog/Public/Write-Warning.ps1 | 11 +-- Tests/Write-Log.Tests.ps1 | 54 ++++++------- 11 files changed, 136 insertions(+), 160 deletions(-) rename PSWriteLog/Private/{Write-InvocationHeader.ps1 => Get-InvocationHeader.ps1} (97%) diff --git a/PSWriteLog/Private/Write-InvocationHeader.ps1 b/PSWriteLog/Private/Get-InvocationHeader.ps1 similarity index 97% rename from PSWriteLog/Private/Write-InvocationHeader.ps1 rename to PSWriteLog/Private/Get-InvocationHeader.ps1 index edcae05..d2df3aa 100644 --- a/PSWriteLog/Private/Write-InvocationHeader.ps1 +++ b/PSWriteLog/Private/Get-InvocationHeader.ps1 @@ -21,7 +21,7 @@ SerializationVersion: 1.1.0.1 ********************** #> -function Write-InvocationHeader { +function Get-InvocationHeader { [CmdletBinding()] param() @@ -56,7 +56,7 @@ function Write-InvocationHeader { } $tmp.FullName | Remove-Item -ErrorAction 'SilentlyContinue' -Force - - Write-Log -Message $header $env:PSWriteLogIncludeInvocationHeader = $null + + return $header } diff --git a/PSWriteLog/Private/Write-Log.ps1 b/PSWriteLog/Private/Write-Log.ps1 index cc01f56..671bfa5 100644 --- a/PSWriteLog/Private/Write-Log.ps1 +++ b/PSWriteLog/Private/Write-Log.ps1 @@ -93,9 +93,12 @@ function global:Write-Log { ) begin { - # Microsoft.PowerShell.Utility\Write-Information "[Write-Log] BoundParameters: $($MyInvocation.BoundParameters | Out-String)" -Tags 'VertigoRay\PSWriteLog','Write-Log' - if ($IncludeInvocationHeader) { - Write-InvocationHeader + Microsoft.PowerShell.Utility\Write-Debug ('[Write-Log] BoundParameters: {0}' -f $($MyInvocation.BoundParameters | Out-String)) + + if ($env:PSWriteLogDisableLogging) { + # If logging is not currently disabled, get out now! + Microsoft.PowerShell.Utility\Write-Debug ('[Write-Log] env:PSWriteLogDisableLogging: {0}' -f $env:PSWriteLogDisableLogging) + return $null } # Get the name of this function @@ -119,11 +122,11 @@ function global:Write-Log { [System.Collections.ArrayList] $legacyMessage = @() - $legacyMessage.Add("[$(& $logDate) $(& $logTime)]") | Out-Null + $legacyMessage.Add(('[{0}]' -f (Get-Date -Format 'O'))) | Out-Null if ($Source) { $legacyMessage.Add("[${Source}]") | Out-Null } - $legacyMessage.Add("[${Component}]") | Out-Null + # $legacyMessage.Add("[${Component}]") | Out-Null $legacyMessage.Add("[${Severity}]") | Out-Null $legacyMessage.Add(($lMessage.Trim() | Out-String)) | Out-Null @@ -136,7 +139,7 @@ function global:Write-Log { [string] $lMessage ) - # Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Source (sb): ${Source}" -Tags 'VertigoRay\PSWriteLog','Write-Log' + Microsoft.PowerShell.Utility\Write-Debug "[Write-Log] Source (sb): ${Source}" $severityMap = @{ # Vaguely based on POSH stream numbers Debug = 5 Error = 3 @@ -162,17 +165,19 @@ function global:Write-Log { )) } - [scriptblock] $getLogLine = { + [scriptblock] $logLine = { param( [string] $sMsg ) ## Choose which log type to write to file - if ($LogType -ieq 'CMTrace') { - return & $cmTraceLogString -lMessage ($sMsg | Out-String).Trim() -lSource $Source + $line = if ($LogType -ieq 'CMTrace') { + & $cmTraceLogString -lMessage ($sMsg | Out-String).Trim() -lSource $Source } else { - return & $legacyLogString -lMessage ($sMsg | Out-String).Trim() -lSource $Source + & $legacyLogString -lMessage ($sMsg | Out-String).Trim() -lSource $Source } + + $line | Out-File -FilePath $FilePath.FullName -Append -NoClobber -Force -Encoding 'UTF8' -ErrorAction 'Stop' } # Create the directory where the log file will be saved @@ -182,28 +187,26 @@ function global:Write-Log { } process { - # Exit function if it is a debug message and 'LogDebugMessage' option is not $true, or if the log directory was not successfully created in 'Begin' block. - if (($DebugMessage -and -not $LogDebugMessage)) { Return } + if ($IncludeInvocationHeader) { + & $logLine -sMsg ("{1}`n{0}`n{1}" -f (Get-InvocationHeader),('#' * 40)) + } foreach ($msg in $Message) { - # Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Source: $Source" -Tags 'VertigoRay\PSWriteLog','Write-Log' - # Write the log entry to the log file if logging is not currently disabled - if (-not $DisableLogging) { - try { - & $getLogLine -sMsg $msg | Out-File -FilePath $FilePath.FullName -Append -NoClobber -Force -Encoding 'UTF8' -ErrorAction 'Stop' - } catch { - if (-not $ContinueOnError) { - throw ('[{0} {1}] [{2}] [{3}] :: Failed to write message [{4}] to the log file [{5}].{6}{7}' -f @( - & $logDate - & $logTime - $CmdletName - $Component - $Msg - $FilePath.FullName - "`n" - Resolve-Error | Out-String - )) - } + Microsoft.PowerShell.Utility\Write-Debug ('[Write-Log] Source: {0}' -f $Source) + try { + & $logLine -sMsg $msg + } catch { + if (-not $ContinueOnError) { + throw ('[{0} {1}] [{2}] [{3}] :: Failed to write message [{4}] to the log file [{5}].{6}{7}' -f @( + & $logDate + & $logTime + $CmdletName + $Component + $Msg + $FilePath.FullName + "`n" + Resolve-Error | Out-String + )) } } } @@ -214,29 +217,29 @@ function global:Write-Log { if ($MaxLogFileSizeMB) { try { [decimal] $LogFileSizeMB = $FilePath.Length/1MB - # Microsoft.PowerShell.Utility\Write-Information "[Write-Log] LogFileSizeMB: $LogFileSizeMB / $MaxLogFileSizeMB" -Tags 'VertigoRay\PSWriteLog','Write-Log' + Microsoft.PowerShell.Utility\Write-Debug "[Write-Log] LogFileSizeMB: $LogFileSizeMB / $MaxLogFileSizeMB" if ($LogFileSizeMB -gt $MaxLogFileSizeMB) { - # Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Log File Needs to be archived ..." -Tags 'VertigoRay\PSWriteLog','Write-Log' + Microsoft.PowerShell.Utility\Write-Debug "[Write-Log] Log File Needs to be archived ..." # Change the file extension to "lo_" [string] $archivedOutLogFile = [IO.Path]::ChangeExtension($FilePath.FullName, 'lo_') # Log message about archiving the log file if ((Get-PSCallStack)[1].Command -ne 'Write-Log') { # Prevent Write-Log from looping more than once. - & $getLogLine -sMsg "Maximum log file size [${MaxLogFileSizeMB} MB] reached. Rename log file to: ${archivedOutLogFile}" | Out-File -FilePath $FilePath.FullName -Append -NoClobber -Force -Encoding 'UTF8' -ErrorAction 'Stop' + & $logLine -sMsg "Maximum log file size [${MaxLogFileSizeMB} MB] reached. Rename log file to: ${archivedOutLogFile}" } # Archive existing log file from .log to .lo_. Overwrites any existing .lo_ file. This is the same method SCCM uses for log files. Move-Item -Path $FilePath.FullName -Destination $archivedOutLogFile -Force -ErrorAction 'Stop' # Start new log file and Log message about archiving the old log file - & $getLogLine -sMsg "Maximum log file size [${MaxLogFileSizeMB} MB] reached. Previous log file was renamed to: ${archivedOutLogFile}" | Out-File -FilePath $FilePath.FullName -Append -NoClobber -Force -Encoding 'UTF8' -ErrorAction 'Stop' + & $logLine -sMsg "Maximum log file size [${MaxLogFileSizeMB} MB] reached. Previous log file was renamed to: ${archivedOutLogFile}" } else { - # Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Log File does not need to be archived." -Tags 'VertigoRay\PSWriteLog','Write-Log' + Microsoft.PowerShell.Utility\Write-Debug "[Write-Log] Log File does not need to be archived." } } catch { # If renaming of file fails, script will continue writing to log file even if size goes over the max file size - # Microsoft.PowerShell.Utility\Write-Information "[Write-Log] Archive Error: ${_}" -Tags 'VertigoRay\PSWriteLog','Write-Log' + Microsoft.PowerShell.Utility\Write-Debug "[Write-Log] Archive Error: ${_}" } } } diff --git a/PSWriteLog/Public/Write-Debug.ps1 b/PSWriteLog/Public/Write-Debug.ps1 index c3edead..bf61637 100644 --- a/PSWriteLog/Public/Write-Debug.ps1 +++ b/PSWriteLog/Public/Write-Debug.ps1 @@ -5,13 +5,7 @@ function global:Write-Debug { [Alias('Msg')] [AllowEmptyString()] [string] - ${Message}, - - [switch] - $NoLog, - - [switch] - $Silent + ${Message} ) begin @@ -28,14 +22,13 @@ function global:Write-Debug { 'Source' = "${invoFile}:$($MyInvocation.ScriptLineNumber)"; } - if (-not $Silent) { + if (-not ($env:PSWriteLogDebugSilent -as [bool])) { try { $outBuffer = $null if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) { $PSBoundParameters['OutBuffer'] = 1 } - $PSBoundParameters.Remove('NoLog') | Out-Null $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Write-Debug', [System.Management.Automation.CommandTypes]::Cmdlet) $scriptCmd = { & $wrappedCmd @PSBoundParameters } $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) @@ -48,13 +41,13 @@ function global:Write-Debug { process { - if (-not $NoLog.isPresent) { + if (-not ($env:PSWriteLogDebugNoLog -as [bool])) { if ((Get-Command 'Write-Log' -ErrorAction 'Ignore') -and ($DebugPreference -ine 'SilentlyContinue')) { Write-Log @writeLog -Message $Message } } - if (-not $Silent) { + if (-not ($env:PSWriteLogDebugSilent -as [bool])) { try { $steppablePipeline.Process($_) } catch { @@ -65,7 +58,7 @@ function global:Write-Debug { end { - if (-not $Silent) { + if (-not ($env:PSWriteLogDebugSilent -as [bool])) { try { $steppablePipeline.End() } catch { diff --git a/PSWriteLog/Public/Write-Error.ps1 b/PSWriteLog/Public/Write-Error.ps1 index 0dd7807..1d885e9 100644 --- a/PSWriteLog/Public/Write-Error.ps1 +++ b/PSWriteLog/Public/Write-Error.ps1 @@ -49,10 +49,7 @@ function global:Write-Error { [Alias('TargetType')] [string] - ${CategoryTargetType}, - - [switch] - $Silent + ${CategoryTargetType} ) begin @@ -69,7 +66,7 @@ function global:Write-Error { 'Source' = "${invoFile}:$($MyInvocation.ScriptLineNumber)"; } - if (-not $Silent) { + if (-not ($env:PSWriteLogErrorSilent -as [bool])) { try { $outBuffer = $null if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) @@ -117,7 +114,7 @@ function global:Write-Error { Write-Log @writeLog -Message ($msg -join ' ') -ErrorAction 'Stop' } - if (-not $Silent) { + if (-not ($env:PSWriteLogErrorSilent -as [bool])) { try { $steppablePipeline.Process($_) } catch { @@ -128,7 +125,7 @@ function global:Write-Error { end { - if (-not $Silent) { + if (-not ($env:PSWriteLogErrorSilent -as [bool])) { try { $steppablePipeline.End() } catch { diff --git a/PSWriteLog/Public/Write-Host.ps1 b/PSWriteLog/Public/Write-Host.ps1 index abb397a..252226e 100644 --- a/PSWriteLog/Public/Write-Host.ps1 +++ b/PSWriteLog/Public/Write-Host.ps1 @@ -15,10 +15,7 @@ function global:Write-Host { ${ForegroundColor}, [System.ConsoleColor] - ${BackgroundColor}, - - [switch] - $Silent + ${BackgroundColor} ) begin @@ -34,7 +31,7 @@ function global:Write-Host { 'Source' = "${invoFile}:$($MyInvocation.ScriptLineNumber)"; } - if (-not $Silent) { + if (-not ($env:PSWriteLogHostSilent -as [bool])) { try { $outBuffer = $null if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) @@ -57,7 +54,7 @@ function global:Write-Host { Write-Log @writeLog -Message $Object } - if (-not $Silent) { + if (-not ($env:PSWriteLogHostSilent -as [bool])) { try { $steppablePipeline.Process($_) } catch { @@ -68,7 +65,7 @@ function global:Write-Host { end { - if (-not $Silent) { + if (-not ($env:PSWriteLogHostSilent -as [bool])) { try { $steppablePipeline.End() } catch { diff --git a/PSWriteLog/Public/Write-Information.ps1 b/PSWriteLog/Public/Write-Information.ps1 index a9975a9..eb8577d 100644 --- a/PSWriteLog/Public/Write-Information.ps1 +++ b/PSWriteLog/Public/Write-Information.ps1 @@ -8,10 +8,7 @@ function global:Write-Information { [Parameter(Position=1)] [string[]] - ${Tags}, - - [switch] - $Silent + ${Tags} ) begin @@ -27,7 +24,7 @@ function global:Write-Information { 'Source' = "${invoFile}:$($MyInvocation.ScriptLineNumber)"; } - if (-not $Silent) { + if (-not ($env:PSWriteLogInformationSilent -as [bool])) { try { $outBuffer = $null if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) @@ -48,13 +45,13 @@ function global:Write-Information { { if ((Get-Command 'Write-Log' -ErrorAction 'Ignore') -and ($InformationPreference -ine 'SilentlyContinue')) { if ($Tags.isPresent) { - Write-Log @writeLog -Message "$MessageData {$($Tags -join ',')}" + Write-Log @writeLog -Message "{$($Tags -join ',')} $MessageData" } else { Write-Log @writeLog -Message "$MessageData" } } - if (-not $Silent) { + if (-not ($env:PSWriteLogInformationSilent -as [bool])) { try { $steppablePipeline.Process($_) } catch { @@ -65,7 +62,7 @@ function global:Write-Information { end { - if (-not $Silent) { + if (-not ($env:PSWriteLogInformationSilent -as [bool])) { try { $steppablePipeline.End() } catch { diff --git a/PSWriteLog/Public/Write-Output.ps1 b/PSWriteLog/Public/Write-Output.ps1 index d77afbb..03abc15 100644 --- a/PSWriteLog/Public/Write-Output.ps1 +++ b/PSWriteLog/Public/Write-Output.ps1 @@ -8,10 +8,7 @@ function global:Write-Output { ${InputObject}, [switch] - ${NoEnumerate}, - - [switch] - $Log + ${NoEnumerate} ) begin @@ -45,7 +42,7 @@ function global:Write-Output { process { - if ((Get-Command 'Write-Log' -ErrorAction 'Ignore') -and $Log.IsPresent) { + if ((Get-Command 'Write-Log' -ErrorAction 'Ignore') -and ($env:PSWriteLogOutputLog -as [bool])) { Write-Log @writeLog -Message ($InputObject | Out-String) } diff --git a/PSWriteLog/Public/Write-Progress.ps1 b/PSWriteLog/Public/Write-Progress.ps1 index 92940ac..5787a75 100644 --- a/PSWriteLog/Public/Write-Progress.ps1 +++ b/PSWriteLog/Public/Write-Progress.ps1 @@ -33,11 +33,7 @@ function global:Write-Progress { ${Completed}, [int] - ${SourceId}, - - [ValidateScript({[enum]::GetValues([System.ConsoleColor]) -icontains $_})] - [string] - ${WriteHostColor} + ${SourceId} ) begin @@ -54,56 +50,58 @@ function global:Write-Progress { 'Source' = "${invoFile}:$($MyInvocation.ScriptLineNumber)"; } - try { - $outBuffer = $null - if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) - { - $PSBoundParameters['OutBuffer'] = 1 + if (-not ($env:PSWriteLogProgessSilent -as [bool])) { + try { + $outBuffer = $null + if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) + { + $PSBoundParameters['OutBuffer'] = 1 + } + $PSBoundParameters.Remove('WriteHostColor') + $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Write-Progress', [System.Management.Automation.CommandTypes]::Cmdlet) + $scriptCmd = {& $wrappedCmd @PSBoundParameters } + $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) + $steppablePipeline.Begin($PSCmdlet) + } catch { + throw } - $PSBoundParameters.Remove('WriteHostColor') - $wrappedCmd = $ExecutionContext.InvokeCommand.GetCommand('Microsoft.PowerShell.Utility\Write-Progress', [System.Management.Automation.CommandTypes]::Cmdlet) - $scriptCmd = {& $wrappedCmd @PSBoundParameters } - $steppablePipeline = $scriptCmd.GetSteppablePipeline($myInvocation.CommandOrigin) - $steppablePipeline.Begin($PSCmdlet) - } catch { - throw } } process { - [System.Collections.ArrayList] $Message = @() - if ($PSBoundParameters.ContainsKey('ParentId')) { $Message.Add("[${ParentId}]") | Out-Null } - if ($PSBoundParameters.ContainsKey('Id')) { $Message.Add("[${Id}]") | Out-Null } - $Message.Add($Activity) | Out-Null - if ($PSBoundParameters.ContainsKey('PercentComplete')) { $Message.Add("${PercentComplete}%") | Out-Null } - if ($PSBoundParameters.ContainsKey('SecondsRemaining')) { $Message.Add("(${SecondsRemaining} Seconds Remaining)") | Out-Null } - $Message.Add(':') | Out-Null - $Message.Add($Status) | Out-Null - $Message.Add(':') | Out-Null - $Message.Add($CurrentOperation) | Out-Null - - if (Get-Command 'Write-Log' -ErrorAction 'Ignore') { - Write-Log @writeLog -Message ($Message -join ' ') - } + if (Get-Command 'Write-Log' -ErrorAction 'Ignore' -and ($ProgressPreference -ine 'SilentlyContinue')) { + [System.Collections.ArrayList] $Message = @() + if ($PSBoundParameters.ContainsKey('ParentId')) { $Message.Add("[${ParentId}]") | Out-Null } + if ($PSBoundParameters.ContainsKey('Id')) { $Message.Add("[${Id}]") | Out-Null } + $Message.Add($Activity) | Out-Null + if ($PSBoundParameters.ContainsKey('PercentComplete')) { $Message.Add("${PercentComplete}%") | Out-Null } + if ($PSBoundParameters.ContainsKey('SecondsRemaining')) { $Message.Add("(${SecondsRemaining} Seconds Remaining)") | Out-Null } + $Message.Add(':') | Out-Null + $Message.Add($Status) | Out-Null + $Message.Add(':') | Out-Null + $Message.Add($CurrentOperation) | Out-Null - if ($WriteHostColor) { - Microsoft.PowerShell.Utility\Write-Host -ForegroundColor $WriteHostColor ($Message -join ' ') + Write-Log @writeLog -Message ($Message -join ' ') } - try { - $steppablePipeline.Process($_) - } catch { - throw + if (-not ($env:PSWriteLogProgessSilent -as [bool])) { + try { + $steppablePipeline.Process($_) + } catch { + throw + } } } end { - try { - $steppablePipeline.End() - } catch { - throw + if (-not ($env:PSWriteLogProgessSilent -as [bool])) { + try { + $steppablePipeline.End() + } catch { + throw + } } } <# diff --git a/PSWriteLog/Public/Write-Verbose.ps1 b/PSWriteLog/Public/Write-Verbose.ps1 index 77486e9..73e1a89 100644 --- a/PSWriteLog/Public/Write-Verbose.ps1 +++ b/PSWriteLog/Public/Write-Verbose.ps1 @@ -5,10 +5,7 @@ function global:Write-Verbose { [Alias('Msg')] [AllowEmptyString()] [string] - ${Message}, - - [switch] - $Silent + ${Message} ) begin @@ -25,7 +22,7 @@ function global:Write-Verbose { 'Source' = "${invoFile}:$($MyInvocation.ScriptLineNumber)"; } - if (-not $Silent) { + if (-not ($env:PSWriteLogVerboseSilent -as [bool])) { try { $outBuffer = $null if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) @@ -48,7 +45,7 @@ function global:Write-Verbose { Write-Log @writeLog -Message $Message } - if (-not $Silent) { + if (-not ($env:PSWriteLogVerboseSilent -as [bool])) { try { $steppablePipeline.Process($_) } catch { @@ -59,7 +56,7 @@ function global:Write-Verbose { end { - if (-not $Silent) { + if (-not ($env:PSWriteLogVerboseSilent -as [bool])) { try { $steppablePipeline.End() } catch { diff --git a/PSWriteLog/Public/Write-Warning.ps1 b/PSWriteLog/Public/Write-Warning.ps1 index 9f6b78b..bd82ff0 100644 --- a/PSWriteLog/Public/Write-Warning.ps1 +++ b/PSWriteLog/Public/Write-Warning.ps1 @@ -5,10 +5,7 @@ function global:Write-Warning { [Alias('Msg')] [AllowEmptyString()] [string] - ${Message}, - - [switch] - $Silent + ${Message} ) begin @@ -25,7 +22,7 @@ function global:Write-Warning { 'Source' = "${invoFile}:$($MyInvocation.ScriptLineNumber)"; } - if (-not $Silent) { + if (-not ($env:PSWriteLogWarningSilent -as [bool])) { try { $outBuffer = $null if ($PSBoundParameters.TryGetValue('OutBuffer', [ref]$outBuffer)) @@ -48,7 +45,7 @@ function global:Write-Warning { Write-Log @writeLog -Message $Message } - if (-not $Silent) { + if (-not ($env:PSWriteLogWarningSilent -as [bool])) { try { $steppablePipeline.Process($_) } catch { @@ -59,7 +56,7 @@ function global:Write-Warning { end { - if (-not $Silent) { + if (-not ($env:PSWriteLogWarningSilent -as [bool])) { try { $steppablePipeline.End() } catch { diff --git a/Tests/Write-Log.Tests.ps1 b/Tests/Write-Log.Tests.ps1 index 92f1232..b518619 100644 --- a/Tests/Write-Log.Tests.ps1 +++ b/Tests/Write-Log.Tests.ps1 @@ -55,10 +55,10 @@ Describe 'Write-Log with parameters' { } } - Context 'Write-Log $Message -Severity 1' { + Context 'Write-Log $Message -Severity ''Info''' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null - Write-Log $script:Message -Severity 1 + Write-Log $script:Message -Severity 'Info' } It "Writes 'type=`"1`" ' to ${script:DefaultLog}" { @@ -66,10 +66,10 @@ Describe 'Write-Log with parameters' { } } - Context 'Write-Log $Message -Severity 1 -LogType Legacy' { + Context 'Write-Log $Message -Severity ''Info'' -LogType Legacy' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null - Write-Log $script:Message -Severity 1 -LogType Legacy + Write-Log $script:Message -Severity 'Info' -LogType Legacy } It "Writes '[Info]' to ${script:DefaultLog}" { @@ -77,10 +77,10 @@ Describe 'Write-Log with parameters' { } } - Context 'Write-Log $Message -Severity 2' { + Context 'Write-Log $Message -Severity ''Warning''' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null - Write-Log $script:Message -Severity 2 + Write-Log $script:Message -Severity 'Warning' } It "Writes 'type=`"2`" ' to ${script:DefaultLog}" { @@ -88,10 +88,10 @@ Describe 'Write-Log with parameters' { } } - Context 'Write-Log $Message -Severity 2 -LogType Legacy' { + Context 'Write-Log $Message -Severity ''Warning'' -LogType Legacy' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null - Write-Log $script:Message -Severity 2 -LogType Legacy + Write-Log $script:Message -Severity 'Warning' -LogType Legacy } It "Writes '[Warning]' to ${script:DefaultLog}" { @@ -99,10 +99,10 @@ Describe 'Write-Log with parameters' { } } - Context 'Write-Log $Message -Severity 3' { + Context 'Write-Log $Message -Severity ''Error''' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null - Write-Log $script:Message -Severity 3 + Write-Log $script:Message -Severity 'Error' } It "Writes 'type=`"3`" ' to ${script:DefaultLog}" { @@ -110,10 +110,10 @@ Describe 'Write-Log with parameters' { } } - Context 'Write-Log $Message -Severity 3 -LogType Legacy' { + Context 'Write-Log $Message -Severity ''Error'' -LogType Legacy' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null - Write-Log $script:Message -Severity 3 -LogType Legacy + Write-Log $script:Message -Severity 'Error' -LogType Legacy } It "Writes '[Error]' to ${script:DefaultLog}" { @@ -154,7 +154,7 @@ Describe 'Write-Log with parameters' { } } - Context 'Write-Log $Message -Component Pester -LogType Legacy' { + Context 'Write-Log $Message -Component Pester -LogType Legacy' -Skip { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null Write-Log $script:Message -Component Pester -LogType Legacy @@ -236,7 +236,7 @@ Describe 'Write-Log with parameters' { } } -Describe 'Write-Log with $PSDefaultParameterValues' { +Describe 'Write-Log with $env:PSWriteLog*' { BeforeAll { $script:DefaultLog = "${TestDrive}\Logs\Write-Log.log" $script:DefaultLog = [IO.Path]::Combine($env:Temp, ('PowerShell {0} {1} {2}.log' -f $PSVersionTable.PSEdition, $PSVersionTable.PSVersion, $MyInvocation.CommandOrigin)) @@ -266,11 +266,11 @@ Describe 'Write-Log with $PSDefaultParameterValues' { } } - Context 'Write-Log $Message -Severity 1' { + Context 'Write-Log $Message -Severity ''Info''' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null $PSDefaultParameterValues = @{} - $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 1) + $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 'Info') Write-Log $script:Message } @@ -279,11 +279,11 @@ Describe 'Write-Log with $PSDefaultParameterValues' { } } - Context 'Write-Log $Message -Severity 1 -LogType Legacy' { + Context 'Write-Log $Message -Severity ''Info'' -LogType Legacy' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null $PSDefaultParameterValues = @{} - $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 1) + $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 'Info') $PSDefaultParameterValues.Set_Item('Write-Log:LogType', 'Legacy') Write-Log $script:Message } @@ -293,11 +293,11 @@ Describe 'Write-Log with $PSDefaultParameterValues' { } } - Context 'Write-Log $Message -Severity 2' { + Context 'Write-Log $Message -Severity ''Warning''' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null $PSDefaultParameterValues = @{} - $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 2) + $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 'Warning') Write-Log $script:Message } @@ -306,11 +306,11 @@ Describe 'Write-Log with $PSDefaultParameterValues' { } } - Context 'Write-Log $Message -Severity 2 -LogType Legacy' { + Context 'Write-Log $Message -Severity ''Warning'' -LogType Legacy' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null $PSDefaultParameterValues = @{} - $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 2) + $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 'Warning') $PSDefaultParameterValues.Set_Item('Write-Log:LogType', 'Legacy') Write-Log $script:Message } @@ -320,11 +320,11 @@ Describe 'Write-Log with $PSDefaultParameterValues' { } } - Context 'Write-Log $Message -Severity 3' { + Context 'Write-Log $Message -Severity ''Error''' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null $PSDefaultParameterValues = @{} - $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 3) + $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 'Error') Write-Log $script:Message } @@ -333,11 +333,11 @@ Describe 'Write-Log with $PSDefaultParameterValues' { } } - Context 'Write-Log $Message -Severity 3 -LogType Legacy' { + Context 'Write-Log $Message -Severity ''Error'' -LogType Legacy' { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null $PSDefaultParameterValues = @{} - $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 3) + $PSDefaultParameterValues.Set_Item('Write-Log:Severity', 'Error') $PSDefaultParameterValues.Set_Item('Write-Log:LogType', 'Legacy') Write-Log $script:Message } @@ -387,7 +387,7 @@ Describe 'Write-Log with $PSDefaultParameterValues' { } } - Context 'Write-Log $Message -Component Pester -LogType Legacy' { + Context 'Write-Log $Message -Component Pester -LogType Legacy' -Skip { BeforeEach { Remove-Item $script:DefaultLog -Force -ErrorAction 'Ignore' | Out-Null $PSDefaultParameterValues = @{}