winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

Write-LogEntry.ps1 (1583B)


      1 Function Write-LogEntry
      2 {
      3     PARAM(
      4         [Parameter(Position=0, Mandatory=$true)]  [string] $LogEntry,
      5         [Parameter(Position=1, Mandatory=$false)] [int]    $Severity=1,
      6         [Parameter(Position=2, Mandatory=$false)] [string] $FontColor="",
      7         [Parameter(Position=3, Mandatory=$false)] [int]    $Indent = 0,
      8         [Parameter(Position=4, Mandatory=$false)] [switch] $NoNewLine
      9     )
     10     BEGIN
     11     {
     12         if($FontColor -eq "") {
     13             switch ($Severity) {
     14                 "1" {
     15                     ## Informational Response
     16                     $FontColor     = "White"
     17                     $MessagePreFix = ""
     18                 }
     19                 "2" {
     20                     ## Warning Response
     21                     $FontColor = "Yellow"
     22                     $MessagePreFix = "WARNING:  "
     23                 }
     24                 "3" {
     25                     ## Error Response
     26                     $FontColor = "Red"
     27                     $MessagePreFix = "ERROR:    "
     28                 }
     29             }
     30         }
     31         ## Combines the logging message and the message type as a prefix
     32         $LogEntry = $MessagePreFix + $LogEntry
     33 
     34         ## Indents the message when viewed on the screen.
     35         $LogEntry = $LogEntry.PadLeft($LogEntry.Length + (2 * $Indent) )
     36     }
     37     PROCESS
     38     {
     39         ## Writes logging to the screen
     40         if($NoNewLine) {
     41             Write-Host -Object $LogEntry -ForegroundColor $FontColor -NoNewline
     42         }
     43         else {
     44             Write-Host -Object $LogEntry -ForegroundColor $FontColor
     45         }
     46     }
     47     END
     48     {
     49         return
     50     }
     51 }