private/Write-HostMessage.ps1
Function Write-HostMessage { [CmdLetBinding()] param ( [Parameter(Mandatory=$true, Position=0)] [string] $Message, [Parameter(Mandatory=$false, Position=1)] [ValidateSet('Error', 'Warning', 'Information', 'Verbose', 'Debug', 'Success')] [string] $Level = 'Information', [switch] $NoNewLine ) begin { $color = (get-host).ui.rawui.ForegroundColor switch ($Level) { 'Error' { $color = 'Red' } 'Warning' { $color = 'Yellow' } 'Information' { $color = 'White' } 'Verbose' { $color = 'Cyan' } 'Success' { $color = 'Green' } 'Debug' { $color = 'DarkGray' } default { throw "Invalid log level: $_" } } } process { Write-Host $Message -ForegroundColor $color -NoNewline:$NoNewLine } } Function Write-HostError { param ( [Parameter(Mandatory=$true, Position=0)] [string] $Message, [switch] $NoNewLine ) process { Write-HostMessage -Message $Message -Level 'Error' -NoNewline:$NoNewLine } } Function Write-HostInfo { param ( [Parameter(Mandatory=$true, Position=0)] [string] $Message, [switch] $NoNewLine ) process { Write-HostMessage -Message $Message -Level 'Information' -NoNewline:$NoNewLine } } Function Write-HostDebug { param ( [Parameter(Mandatory=$true, Position=0)] [string] $Message, [switch] $NoNewLine ) process { Write-HostMessage -Message $Message -Level 'Debug' -NoNewline:$NoNewLine } } Function Write-HostWarning { param ( [Parameter(Mandatory=$true, Position=0)] [string] $Message, [switch] $NoNewLine ) process { Write-HostMessage -Message $Message -Level 'Warning' -NoNewline:$NoNewLine } } Function Write-HostSuccess { param ( [Parameter(Mandatory=$true, Position=0)] [string] $Message, [switch] $NoNewLine ) process { Write-HostMessage -Message $Message -Level 'Success' -NoNewline:$NoNewLine } } |