SimplePSLogger.Console/SimplePSLogger.Console.psm1
<#
.SYNOPSIS Colored Console logging provider for SimplePSLogger logger This provider writes colored messages to the console by using powershell's default Write-* functions .DESCRIPTION TODO: add more details More details .PARAMETER Name SimplePSLogger action execution id which is used to identify executing action .PARAMETER Level Log level : allowed values are - "verbose", "debug", "information", "warning", "error", "critical", "none" TODO : add more infor for each level .PARAMETER Message Log message : String - plain text string OtherTypes - json serialized string .EXAMPLE TODO : Add examples .NOTES Author: Ganesh Raskar #> function New-Console-Logger { [CmdletBinding()] param ( [Parameter(Mandatory = $true, HelpMessage = "Name of the SimplePSLogger instance")] [string] $Name, [Parameter(Mandatory = $false, HelpMessage = "Log level, default value is information")] [string] $Level, [Parameter(Mandatory = $true, HelpMessage = "Log message")] [string] $Message ) $logMessage = "$((Get-Date).ToUniversalTime().ToString("yyyy/MM/dd HH:mm:ss:ffff tt")) $Name $($Level): $($Message.Trim())" $InformationPreference = "Continue" <# I don't like prepended WARNING, IFORMATION etc by powershell # Reference - https://devblogs.microsoft.com/scripting/weekend-scripter-customize-powershell-title-and-prompt/ # TODO : refactor #> switch -Exact ($Level) { 'verbose' { $prevColor = $host.ui.RawUI.ForegroundColor $host.ui.RawUI.ForegroundColor = "White" Write-Information "$logMessage" -InformationAction Continue $host.ui.RawUI.ForegroundColor = $prevColor break } 'debug' { $prevColor = $host.ui.RawUI.ForegroundColor $host.ui.RawUI.ForegroundColor = "White" Write-Information "$logMessage" -InformationAction Continue $host.ui.RawUI.ForegroundColor = $prevColor break } 'information' { $prevColor = $host.ui.RawUI.ForegroundColor $host.ui.RawUI.ForegroundColor = "Cyan" Write-Information "$logMessage" -InformationAction Continue $host.ui.RawUI.ForegroundColor = $prevColor break } 'error' { $prevColor = $host.ui.RawUI.ForegroundColor $host.ui.RawUI.ForegroundColor = "Red" Write-Information "$logMessage" -InformationAction Continue $host.ui.RawUI.ForegroundColor = $prevColor break } 'warning' { $prevColor = $host.ui.RawUI.ForegroundColor $host.ui.RawUI.ForegroundColor = "Yellow" Write-Information "$logMessage" -InformationAction Continue $host.ui.RawUI.ForegroundColor = $prevColor break } 'critical' { $prevColor = $host.ui.RawUI.ForegroundColor $host.ui.RawUI.ForegroundColor = "DarkRed" Write-Information "$logMessage" -InformationAction Continue $host.ui.RawUI.ForegroundColor = $prevColor break } Default { $prevColor = $host.ui.RawUI.ForegroundColor $host.ui.RawUI.ForegroundColor = "Cyan" Write-Information "$logMessage" -InformationAction Continue $host.ui.RawUI.ForegroundColor = $prevColor } } } Export-ModuleMember -Function New-Console-Logger # SIG # Begin signature block # MIIYYQYJKoZIhvcNAQcCoIIYUjCCGE4CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR # AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU1E3LdQ9c52C4FsZVbETlp6dm # z0+gghKzMIIFcDCCA1igAwIBAgIQZDtcNubuNpVEfXOVHbciTzANBgkqhkiG9w0B # AQsFADBQMSUwIwYDVQQDDBxHYW5lc2ggUmFza2FyIFNpbXBsZVBTTG9nZ2VyMScw # JQYJKoZIhvcNAQkBFhhnYW5lc2hyYXNrYXJAb3V0bG9vay5jb20wHhcNMjAwNzA0 # MTgzMjE0WhcNMjEwNzA0MTg1MjE0WjBQMSUwIwYDVQQDDBxHYW5lc2ggUmFza2Fy # IFNpbXBsZVBTTG9nZ2VyMScwJQYJKoZIhvcNAQkBFhhnYW5lc2hyYXNrYXJAb3V0 # bG9vay5jb20wggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCywhH9ot8P # 9i7rClMbjRwIH1DeVotpNCscFvcSqEbMo3AtJ0WFOb13Xt/g1d0axBa3DvriedVR # KF2AD0U8jGIsToPBnIdBKVXQ72CN+i1BHrqu9DOI7+csE0hVFAqYCv7qIXgAGued # FQOe1oD5q3H3GlzLDfwhk/cdLCt+WEgzWdtTca8kirNoRftS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