From 545701705d2d90db7dcc37949df7abde3bb89507 Mon Sep 17 00:00:00 2001 From: dyoder Date: Sat, 19 Sep 2020 16:40:07 -0400 Subject: [PATCH] cleanup logging --- Tools.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Tools.ps1 b/Tools.ps1 index 92c1558..d3f0cf7 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -26,12 +26,13 @@ Function Log { param( [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$Message, - [Parameter(Mandatory=$false)][switch]$Error, + [Parameter(Mandatory=$false)][switch]$Error=$false, [Parameter(Mandatory=$false)][string]$LogName ) -If ( $Error ) { $LogEntry = "{0} - Error: {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message } -Else { $LogEntry = "{0} - {1}" -f (Get-Date -Format "yyyy-MM-dd HH:mm:ss"), $Message } -If ($LogName ) +$Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" +If ( $Error ) { $LogEntry = "${Timestamp} - Error: ${Message}" } +Else { $LogEntry = "${Timestamp} - ${Message}" } +If ( $LogName ) { $LogFile = "${MSPLogs}\${LogFilePrefix}-${LogName}.log" If (! (Test-Path $LogFile) ) { New-Item -Path $LogFile -ItemType File -Force | Out-Null }