-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogLib.ps1
More file actions
46 lines (38 loc) · 1.42 KB
/
LogLib.ps1
File metadata and controls
46 lines (38 loc) · 1.42 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
################################################
# Get timestamp for Logs
function getTime() {
################################################
return "[{0:MM/dd/yyyy} {0:HH:mm:ss.fff K}]" -f (Get-Date)
}
#Get current location of script
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$logFile = Join-Path $scriptPath $logFilename
################################################
#log message to Console and log File
function log($message, $warning = $false) {
################################################
$formattedMessage = "$(getTime) ${message}"
if(!$warning){
Write-Host $formattedMessage
Write-Output $formattedMessage | Out-file $logFile -append
} else{
Write-Warning $formattedMessage
Write-Output "WARNING: ${formattedMessage}" | Out-file $logFile -append
}
}
################################################
#debug message to Console and log File
function debug($message) {
################################################
if ( $CxDebug ) {
log( "$message" )
}
}
################################################
#error message to Console and log File
function error($message, $warning = $false) {
################################################
$formattedMessage = "$(getTime) ${message}"
Write-Error $formattedMessage
Write-Output "ERROR: ${formattedMessage}" | Out-file $logFile -append
}