Skip to content

Commit 68c0efd

Browse files
author
EsOsO
committed
Merge branch 'dev'
# Conflicts: # Logging/targets/WebexTeams.ps1
2 parents 8675e82 + eea5c4c commit 68c0efd

4 files changed

Lines changed: 30 additions & 27 deletions

File tree

Logging/Logging.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Description = 'Powershell Logging Module'
6969
# NestedModules = @()
7070

7171
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72-
# FunctionsToExport = @('Use-LogMessage','Add-LoggingLevel','Add-LoggingTarget','Get-LoggingMessageCount','Get-LoggingCallerScope','Get-LoggingDefaultFormat','Get-LoggingDefaultLevel','Get-LoggingTarget','Get-LoggingAvailableTarget','Set-LoggingCallerScope','Set-LoggingCustomTarget','Set-LoggingDefaultFormat','Set-LoggingDefaultLevel','Wait-Logging','Write-Log')
72+
FunctionsToExport = @('Add-LoggingLevel','Add-LoggingTarget','Get-LoggingAvailableTarget','Get-LoggingCallerScope','Get-LoggingDefaultFormat','Get-LoggingDefaultLevel','Get-LoggingTarget','Set-LoggingCallerScope','Set-LoggingCustomTarget','Set-LoggingDefaultFormat','Set-LoggingDefaultLevel','Wait-Logging','Write-Log')
7373

7474
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
7575
CmdletsToExport = @()

Logging/private/Start-LoggingManager.ps1

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ function Start-LoggingManager {
5555
Invoke-Command -ScriptBlock $Logger -ArgumentList @($Log, $TargetConfiguration)
5656
}
5757
}
58-
} catch {
58+
}
59+
catch {
5960
$ParentHost.UI.WriteErrorLine($_)
60-
} finally {
61+
}
62+
finally {
6163
$ParentHost.NotifyEndApplication()
6264
}
6365
}
@@ -70,22 +72,18 @@ function Start-LoggingManager {
7072

7173
#region Handle Module Removal
7274
$OnRemoval = {
73-
$Script:LoggingEventQueue.CompleteAdding()
74-
$Script:LoggingEventQueue.Dispose()
75-
76-
[void] $Script:LoggingRunspace.Powershell.EndInvoke($LoggingRunspace.Handle)
77-
[void] $Script:LoggingRunspace.Powershell.Dispose()
78-
79-
Remove-Variable Logging -Scope Script -Force
80-
Remove-Variable Defaults -Scope Script -Force
81-
Remove-Variable LevelNames -Scope Script -Force
82-
Remove-Variable LoggingRunspace -Scope Script -Force
83-
Remove-Variable LoggingEventQueue -Scope Script -Force
75+
(Get-Module Logging).Invoke({
76+
Wait-Logging
77+
Stop-LoggingManager
78+
})
8479

8580
[System.GC]::Collect()
8681
}
8782

83+
# This scriptblock would be called within the module scope
8884
$ExecutionContext.SessionState.Module.OnRemove += $OnRemoval
89-
Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $OnRemoval
85+
86+
# This scriptblock would be called within the global scope and wouldn't have access to internal module variables and functions that we need
87+
$Script:LoggingRunspace.EngineEvent = Register-EngineEvent -SourceIdentifier ([System.Management.Automation.PsEngineEvent]::Exiting) -Action $OnRemoval
9088
#endregion Handle Module Removal
9189
}

Logging/targets/WebexTeams.ps1

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
@{
2-
Name = 'WebexTeams'
2+
Name = 'WebexTeams'
33
Configuration = @{
44
BotToken = @{Required = $true; Type = [string]; Default = $null }
5-
RoomID = @{Required = $true; Type = [string]; Default = $null }
6-
Icons = @{Required = $false; Type = [hashtable]; Default = @{
5+
RoomID = @{Required = $true; Type = [string]; Default = $null }
6+
Icons = @{Required = $false; Type = [hashtable]; Default = @{
77
'ERROR' = '🚨'
88
'WARNING' = '⚠️'
99
'INFO' = 'ℹ️'
1010
'DEBUG' = '🔎'
1111
}
1212
}
13-
Level = @{Required = $false; Type = [string]; Default = $Logging.Level}
14-
Format = @{Required = $false; Type = [string]; Default = $Logging.Format}
13+
Level = @{Required = $false; Type = [string]; Default = $Logging.Level }
14+
Format = @{Required = $false; Type = [string]; Default = $Logging.Format }
1515
}
16-
Logger = {
16+
Logger = {
1717
param(
1818
[hashtable] $Log,
1919
[hashtable] $Configuration
2020
)
2121
# Build the Message body
2222
$body = @{
23-
roomId=$Configuration.RoomId
24-
text=$Configuration.Icons[$Log.Level]+" "+$(Replace-Token -String $Configuration.Format -Source $Log)
23+
roomId = $Configuration.RoomId
24+
text = $Configuration.Icons[$Log.Level] + " " + $(Replace-Token -String $Configuration.Format -Source $Log)
2525
}
2626

2727
# Convert to JSON
28-
$json=$body | ConvertTo-Json
28+
$json = $body | ConvertTo-Json
2929
# Send Message to Cisco Webex API - UTF8 Handling for Emojiis
3030
Invoke-RestMethod -Method Post `
31-
-Headers @{"Authorization"="Bearer $($Configuration.BotToken)"} `
32-
-ContentType "application/json" -Body ([System.Text.Encoding]::UTF8.GetBytes($json)) `
33-
-Uri "https://api.ciscospark.com/v1/messages"
31+
-Headers @{"Authorization" = "Bearer $($Configuration.BotToken)" } `
32+
-ContentType "application/json" -Body ([System.Text.Encoding]::UTF8.GetBytes($json)) `
33+
-Uri "https://api.ciscospark.com/v1/messages"
3434
}
3535
}

docs/RELEASE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
- [NEW] added target for Azure Log Analytics Workspace (thx to @manualbashing)
3+
- [NEW] added target for Webex Teams (thx to @itshorty)
4+
- [FIX] fixed module autoload (thx to @Tadas)
5+
- [FIX] module don't hang shell exit (thx to @Tadas) #82

0 commit comments

Comments
 (0)