From 51fd370f9d36af7b09b698a2a93385a08f193b7f Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Wed, 25 Jun 2025 00:20:23 -0400 Subject: [PATCH] Update StackMonkey.ps1 --- StackMonkey.ps1 | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index e03e98f..e90979b 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -120,6 +120,13 @@ function Get-DattoApiCredentials { } } +#region Logging Helpers + +# Initialize a global in-memory log cache +if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.ArrayList])) { + $Global:LogCache = [System.Collections.ArrayList]::new() +} + # Core Write-Log function (advanced with event-log support) function Write-LogHelper { [CmdletBinding()] @@ -158,6 +165,15 @@ function Write-LogHelper { } } +# Hybrid wrapper: uses your module's Write-Log if available, else falls back +if (Get-Command Write-Log -ErrorAction SilentlyContinue) { + function Write-LogHybrid { param($Message,$Level,$TaskCategory,$LogToEvent) Write-Log @PSBoundParameters } +} else { + function Write-LogHybrid { param($Message,$Level,$TaskCategory,$LogToEvent) Write-LogHelper @PSBoundParameters } +} + +#endregion + # ───────────────────────────────────────────────────────────────────────── # 3) MAIN LOGIC (Toolkit vs Datto vs UI) # ───────────────────────────────────────────────────────────────────────── @@ -262,24 +278,6 @@ $Global:Tasks = @( #endregion -#region Logging Helpers - -# Initialize a global in-memory log cache -if (-not $Global:LogCache -or -not ($Global:LogCache -is [System.Collections.ArrayList])) { - $Global:LogCache = [System.Collections.ArrayList]::new() -} - - - -# Hybrid wrapper: uses your module's Write-Log if available, else falls back -if (Get-Command Write-Log -ErrorAction SilentlyContinue) { - function Write-LogHybrid { param($Message,$Level,$TaskCategory,$LogToEvent) Write-Log @PSBoundParameters } -} else { - function Write-LogHybrid { param($Message,$Level,$TaskCategory,$LogToEvent) Write-LogHelper @PSBoundParameters } -} - -#endregion - # If we got here, it's the UI set—launch browser + listener: # ——— UI fallback starts here ———