-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeeLogger.ps1
More file actions
67 lines (59 loc) · 1.76 KB
/
Copy pathLeeLogger.ps1
File metadata and controls
67 lines (59 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
####################################
# Logging and Output Function
####################################
<#
Requirements: Log file path set for variable $logfile
Usage: Generates output for both the console and for a log file
Example: LoggerLee -Text "error message or $ErrorMsg" -Logtype "error"
Author(s): Lee Dickey
#>
function LoggerLee() {
[CmdletBinding()]
param (
[parameter(Mandatory=$True)] [String]$text,
[ValidateSet("low","info","warning","error","success")][string]$logType = "info",
[ValidateSet("newline","nonewline")][string]$linebreak = "newline",
[string]$logfile = "c:\log_" + (Get-Date -UFormat %Y-%m-%d) + ".log"
)
Switch ($logType)
{
"warning" {
$color = "yellow";
$bgcolor = "black";
}
"error" {
$color = "red";
$bgcolor = "black";
}
"info" {
$color = "white";
$bgcolor = "blue";
}
"success" {
$color = "Green";
$bgcolor = "DarkBlue";
}
"low" {
$color = "DarkGray";
$bgcolor = "Darkblue";
}
}
Switch ($linebreak)
{
"nonewline" {
$nobreak = "-NoNewLine";
}
"newline" {
$nobreak = "";
}
}
$LogTime = get-date -Format g
#$logfile = "c:\allowed\scripts\AAATestingSTuff.log"
if ($logtype -eq "low")
{ write-host "$Text" -ForegroundColor $color -nonewline
if ($linebreak -eq "newline") {write-host ""} }
else
{ Write-Output "`n >> $LogTime - $Text" | out-file $logfile -Append;
write-host "$Text" -ForegroundColor $color -BackgroundColor $bgcolor -nonewline
if ($linebreak -eq "newline") {write-host ""} }
}