Skip to content

Commit 32c3108

Browse files
committed
Cleaning up 'Write-ScreenInfo', setting $Global:PSLog_NoNewLine back to $false only if a message was written to the screen.
1 parent 4222aa0 commit 32c3108

File tree

1 file changed

+72
-35
lines changed

1 file changed

+72
-35
lines changed

PSLog/PSLog.psm1

+72-35
Original file line numberDiff line numberDiff line change
@@ -1120,8 +1120,6 @@ function Write-ScreenInfo
11201120

11211121
[switch]$NoNewLine,
11221122

1123-
[int]$Indent,
1124-
11251123
[switch]$TaskStart,
11261124

11271125
[switch]$TaskEnd,
@@ -1166,79 +1164,118 @@ function Write-ScreenInfo
11661164
$TimeDelta2 = (Get-Date) - $Global:taskStart[-1]
11671165
}
11681166

1169-
$TimeDeltaString = '{0:d2}:{1:d2}:{2:d2}' -f $TimeDelta.Hours, $TimeDelta.Minutes, $TimeDelta.Seconds
1170-
$TimeDeltaString2 = '{0:d2}:{1:d2}:{2:d2}.{3:d3}' -f $TimeDelta2.Hours, $TimeDelta2.Minutes, $TimeDelta2.Seconds, $TimeDelta2.Milliseconds
1167+
$timeDeltaString = '{0:d2}:{1:d2}:{2:d2}' -f $TimeDelta.Hours, $TimeDelta.Minutes, $TimeDelta.Seconds
1168+
$timeDeltaString2 = '{0:d2}:{1:d2}:{2:d2}.{3:d3}' -f $TimeDelta2.Hours, $TimeDelta2.Minutes, $TimeDelta2.Seconds, $TimeDelta2.Milliseconds
11711169

11721170
$date = Get-Date
1173-
$TimeCurrent = '{0:d2}:{1:d2}:{2:d2}' -f $date.Hour, $date.Minute, $date.Second
1171+
$timeCurrent = '{0:d2}:{1:d2}:{2:d2}' -f $date.Hour, $date.Minute, $date.Second
11741172

11751173
if ($NoNewLine)
11761174
{
1177-
if ($Global:labDeploymentNoNewLine)
1175+
if ($Global:PSLog_NoNewLine)
11781176
{
11791177
switch ($Type)
11801178
{
1181-
Error { Write-Host $message -NoNewline -ForegroundColor Red}
1182-
Warning { Write-Host $message -NoNewline -ForegroundColor DarkYellow }
1183-
Info { Write-Host $message -NoNewline }
1184-
Debug { if ($DebugPreference -eq 'Continue') { Write-Host $message -NoNewline -ForegroundColor Cyan } }
1185-
Verbose { if ($VerbosePreference -eq 'Continue') { Write-Host $message -NoNewline -ForegroundColor Cyan } }
1179+
Error { Write-Host $Message -NoNewline -ForegroundColor Red}
1180+
Warning { Write-Host $Message -NoNewline -ForegroundColor DarkYellow }
1181+
Info { Write-Host $Message -NoNewline }
1182+
Debug { if ($DebugPreference -eq 'Continue') { Write-Host $Message -NoNewline -ForegroundColor Cyan } }
1183+
Verbose { if ($VerbosePreference -eq 'Continue') { Write-Host $Message -NoNewline -ForegroundColor Cyan } }
11861184
}
11871185
}
11881186
else
11891187
{
1190-
if ($Global:indent -gt 0) { $Message = (' ' * ($Global:indent - 1)) + '- ' + $message }
1188+
if ($Global:PSLog_Indent -gt 0) { $Message = (' ' * ($Global:PSLog_Indent - 1)) + '- ' + $Message }
11911189

11921190
switch ($Type)
11931191
{
1194-
Error { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" -NoNewline -ForegroundColor Red }
1195-
Warning { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" -NoNewline -ForegroundColor Yellow }
1196-
Info { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" -NoNewline }
1197-
Debug { if ($DebugPreference -eq 'Continue') { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" -NoNewline -ForegroundColor Cyan } }
1198-
Verbose { if ($VerbosePreference -eq 'Continue') { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" -NoNewline -ForegroundColor Cyan } }
1192+
Error { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $Message" -NoNewline -ForegroundColor Red }
1193+
Warning { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $Message" -NoNewline -ForegroundColor Yellow }
1194+
Info { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $Message" -NoNewline }
1195+
Debug { if ($DebugPreference -eq 'Continue') { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $Message" -NoNewline -ForegroundColor Cyan } }
1196+
Verbose { if ($VerbosePreference -eq 'Continue') { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $Message" -NoNewline -ForegroundColor Cyan } }
11991197
}
12001198

12011199
}
1202-
$Global:labDeploymentNoNewLine = $true
1200+
$Global:PSLog_NoNewLine = $true
12031201
}
12041202
else
12051203
{
1206-
if ($Global:labDeploymentNoNewLine)
1204+
if ($Global:PSLog_NoNewLine)
12071205
{
12081206
switch ($Type)
12091207
{
1210-
Error { $Message | ForEach-Object { Write-Host $_ -ForegroundColor Red } }
1211-
Warning { $Message | ForEach-Object { Write-Host $_ -ForegroundColor Yellow } }
1212-
Info { $Message | ForEach-Object { Write-Host $_ } }
1213-
Verbose { if ($VerbosePreference -eq 'Continue') { $Message | ForEach-Object { Write-Host $_ -ForegroundColor Cyan } } }
1214-
Debug { if ($DebugPreference -eq 'Continue') { $Message | ForEach-Object { Write-Host $_ -ForegroundColor Cyan } } }
1208+
Error {
1209+
$Message | ForEach-Object { Write-Host $_ -ForegroundColor Red }
1210+
$Global:PSLog_NoNewLine = $false
1211+
}
1212+
Warning {
1213+
$Message | ForEach-Object { Write-Host $_ -ForegroundColor Yellow }
1214+
$Global:PSLog_NoNewLine = $false
1215+
}
1216+
Info {
1217+
$Message | ForEach-Object { Write-Host $_ }
1218+
$Global:PSLog_NoNewLine = $false
1219+
}
1220+
Verbose {
1221+
if ($VerbosePreference -eq 'Continue')
1222+
{
1223+
$Message | ForEach-Object { Write-Host $_ -ForegroundColor Cyan }
1224+
$Global:PSLog_NoNewLine = $false
1225+
}
1226+
}
1227+
Debug {
1228+
if ($DebugPreference -eq 'Continue')
1229+
{
1230+
$Message | ForEach-Object { Write-Host $_ -ForegroundColor Cyan }
1231+
$Global:PSLog_NoNewLine = $false
1232+
}
1233+
}
12151234
}
12161235
}
12171236
else
12181237
{
1219-
if ($Global:indent -gt 0) { $Message = (' '*($Global:indent-1)) + '- ' + $message }
1238+
if ($Global:PSLog_Indent -gt 0) { $Message = (' ' * ($Global:PSLog_Indent-1)) + '- ' + $Message }
12201239
switch ($Type)
12211240
{
1222-
Error { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" -ForegroundColor Red }
1223-
Warning { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" -ForegroundColor Yellow }
1224-
Info { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" }
1225-
Debug { if ($DebugPreference -eq 'Continue') { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" -ForegroundColor Cyan } }
1226-
Verbose { if ($VerbosePreference -eq 'Continue') { Write-Host "$TimeCurrent|$TimeDeltaString|$TimeDeltaString2| $message" -ForegroundColor Cyan } }
1241+
Error
1242+
{
1243+
$Message | ForEach-Object { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $_" -ForegroundColor Red }
1244+
}
1245+
Warning {
1246+
$Message | ForEach-Object { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $_" -ForegroundColor Yellow }
1247+
}
1248+
Info {
1249+
$Message | ForEach-Object { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $_" }
1250+
}
1251+
Debug
1252+
{
1253+
if ($DebugPreference -eq 'Continue')
1254+
{
1255+
$Message | ForEach-Object { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $_" -ForegroundColor Cyan }
1256+
}
1257+
}
1258+
Verbose
1259+
{
1260+
if ($VerbosePreference -eq 'Continue')
1261+
{
1262+
$Message | ForEach-Object { Write-Host "$timeCurrent|$timeDeltaString|$timeDeltaString2| $_" -ForegroundColor Cyan }
1263+
}
1264+
}
12271265
}
12281266
}
1229-
$Global:labDeploymentNoNewLine = $false
12301267
}
12311268

12321269
if ($TaskStart)
12331270
{
1234-
$Global:indent++
1271+
$Global:PSLog_Indent++
12351272
}
12361273

12371274
if ($TaskEnd)
12381275
{
1239-
$Global:indent--
1240-
if ($Global:indent -lt 0) { $Global:indent = 0 }
1276+
$Global:PSLog_Indent--
1277+
if ($Global:PSLog_Indent -lt 0) { $Global:PSLog_Indent = 0 }
12411278
}
12421279

12431280
}
1244-
#endregion function Write-ScreenInfo
1281+
#endregion Write-ScreenInfo

0 commit comments

Comments
 (0)