mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-07-16 17:00:43 +00:00
* Harden Pester CI and discard runspace return values * Add prioritized test backlog * Add WinUtil action logging * Add config integrity tests * Add XAML control wiring tests * Add registry and service helper tests * Add package manager tests * Add runspace behavior tests * Add tweak orchestration tests * Add install workflow tests * Add update profile tests * Add AppX removal tests * Log package installer output * Add UI state helper tests * Pin Pester test runner version * Expand Win11 Creator tests * Add preferences and theme tests * Add search filter tests * Add compile contract tests * Use single WinUtil session log * Remove installer output logging helper * Handle locked WinUtil transcript log * Avoid appending to active transcript log * Log install uninstall package identities
82 lines
2.6 KiB
PowerShell
82 lines
2.6 KiB
PowerShell
function Write-WinUtilLog {
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
Writes a timestamped WinUtil log entry to the active session log.
|
|
|
|
.PARAMETER Message
|
|
The message to write.
|
|
|
|
.PARAMETER Level
|
|
The severity level for the log entry.
|
|
|
|
.PARAMETER Component
|
|
The WinUtil component producing the log entry.
|
|
|
|
#>
|
|
param (
|
|
[Parameter(Mandatory = $true)]
|
|
[string]$Message,
|
|
|
|
[ValidateSet("INFO", "WARN", "ERROR", "DEBUG")]
|
|
[string]$Level = "INFO",
|
|
|
|
[string]$Component = "WinUtil"
|
|
)
|
|
|
|
try {
|
|
$logPath = $null
|
|
$transcriptPath = $null
|
|
if ($null -ne $sync -and $sync.ContainsKey("logPath")) {
|
|
$logPath = $sync.logPath
|
|
}
|
|
|
|
if ($null -ne $sync -and $sync.ContainsKey("transcriptPath")) {
|
|
$transcriptPath = $sync.transcriptPath
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($logPath) -and -not [string]::IsNullOrWhiteSpace($transcriptPath)) {
|
|
$logPath = $transcriptPath
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($logPath) -and $null -ne $sync -and $sync.ContainsKey("winutildir")) {
|
|
$logDirectory = Join-Path $sync.winutildir "logs"
|
|
$logPath = Join-Path $logDirectory "winutil_$(Get-Date -Format "yyyy-MM-dd_HH-mm-ss").log"
|
|
$sync.logPath = $logPath
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($logPath) -and -not [string]::IsNullOrWhiteSpace($env:LocalAppData)) {
|
|
if ([string]::IsNullOrWhiteSpace($script:WinUtilLogPath)) {
|
|
$logDirectory = Join-Path (Join-Path $env:LocalAppData "winutil") "logs"
|
|
$script:WinUtilLogPath = Join-Path $logDirectory "winutil_$(Get-Date -Format "yyyy-MM-dd_HH-mm-ss").log"
|
|
}
|
|
$logPath = $script:WinUtilLogPath
|
|
}
|
|
|
|
if ([string]::IsNullOrWhiteSpace($logPath)) {
|
|
return
|
|
}
|
|
|
|
$logDirectory = Split-Path -Path $logPath -Parent
|
|
if (-not (Test-Path $logDirectory)) {
|
|
New-Item -Path $logDirectory -ItemType Directory -Force | Out-Null
|
|
}
|
|
|
|
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
|
|
$line = "[$timestamp] [$Level] [$Component] $Message"
|
|
|
|
if (-not [string]::IsNullOrWhiteSpace($transcriptPath) -and $logPath -eq $transcriptPath) {
|
|
Write-Host $line
|
|
return
|
|
}
|
|
|
|
try {
|
|
Add-Content -Path $logPath -Value $line -Encoding UTF8 -ErrorAction Stop
|
|
} catch [System.IO.IOException] {
|
|
Write-Host $line
|
|
}
|
|
} catch {
|
|
Write-Warning "Unable to write WinUtil log entry: $($_.Exception.Message)"
|
|
}
|
|
}
|