Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefajers authored Jan 18, 2024
1 parent de37d3d commit 13b7a5c
Showing 1 changed file with 39 additions and 51 deletions.
90 changes: 39 additions & 51 deletions src/internal/functions/Write-AzOpsMessage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@

[CmdletBinding()]
param (
[Parameter(Mandatory = $false)]
[bool]
$ApplicationInsights = (Get-PSFConfigValue -FullName 'AzOps.Core.ApplicationInsights'),
[Parameter(Mandatory = $false)]
[hashtable]
$Data,
[Parameter(Mandatory = $false)]
[System.Management.Automation.ErrorRecord]
$ErrorRecord,
[Parameter(Mandatory = $true)]
Expand All @@ -43,16 +46,22 @@
[Parameter(Mandatory = $true)]
[string]
$LogString,
[Parameter(Mandatory = $false)]
[string[]]
$LogStringValues,
[Parameter(Mandatory = $false)]
[int]
$Metric,
[Parameter(Mandatory = $false)]
[string]
$MetricName,
[Parameter(Mandatory = $false)]
[string]
$FunctionName,
[Parameter(Mandatory = $false)]
[string]
$ModuleName,
[Parameter(Mandatory = $false)]
[string]
$Target
)
Expand All @@ -67,56 +76,22 @@
}
process {
# Evaluate message verbosity
switch ($LogLevel) {
"Warning" {
[int]$intLevel = "666"
break
}
"Error" {
[int]$intLevel = "667"
break
}
"Critical" {
[int]$intLevel = "1"
break
}
{ ($_ -eq "Important") -or ($_ -eq "Output") -or ($_ -eq "Host") } {
[int]$intLevel = "2"
break
}
"Significant" {
[int]$intLevel = "3"
break
}
"VeryVerbose" {
[int]$intLevel = "4"
break
}
"Verbose" {
[int]$intLevel = "5"
break
}
"SomewhatVerbose" {
[int]$intLevel = "6"
break
}
"System" {
[int]$intLevel = "7"
break
}
"Debug" {
[int]$intLevel = "8"
break
}
"InternalComment" {
[int]$intLevel = "9"
break
}
default {
[int]$intLevel = "1"
break
}
$logLevels = @{
"Critical" = "1"
"Debug" = "8"
"Error" = "667"
"Host" = "2"
"Important" = "2"
"InternalComment" = "9"
"Output" = "2"
"Significant" = "3"
"SomewhatVerbose" = "6"
"System" = "7"
"Verbose" = "5"
"VeryVerbose" = "4"
"Warning" = "666"
}
[int]$intLevel = $logLevels[$LogLevel]
[int]$messageInfo = Get-PSFConfigValue -FullName 'PSFramework.Message.Info.Maximum'
if (($messageInfo -lt $intLevel) -or ([PSFramework.Message.MessageHost]::MinimumInformation -gt $intLevel) -and ($intLevel -notin 666..667)) {
# Message is below desired log verbosity, skip
Expand All @@ -125,8 +100,21 @@
# Generate unique logTag information, used to identify each log entry
$logTag = (New-Guid).Guid + '-' + (Get-Date).TimeOfDay.TotalMilliseconds
# Pass information to Write-PSFMessage, to emit local log
Write-PSFMessage -Level $LogLevel -String $LogString -StringValues $LogStringValues -Tag $logTag -ModuleName $ModuleName -FunctionName $FunctionName -File $File -Line $Line -Target $Target -ErrorRecord $ErrorRecord -Data $Data
if ($env:APPLICATIONINSIGHTS_CONNECTION_STRING -ne '' -and $ApplicationInsights) {
$params = @{
Level = $LogLevel
String = $LogString
StringValues = $LogStringValues
Tag = $logTag
ModuleName = $ModuleName
FunctionName = $FunctionName
File = $File
Line = $Line
Target = $Target
ErrorRecord = $ErrorRecord
Data = $Data
}
Write-PSFMessage @params
if ($env:APPLICATIONINSIGHTS_CONNECTION_STRING -ne '' -and $ApplicationInsights -eq $true) {
# Initiate export of log to ApplicationInsights
try {
# Gather log generated by Write-PSFMessage with retry/backoff logic
Expand Down

0 comments on commit 13b7a5c

Please sign in to comment.