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 ———