-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathHelper_Logging.ps1
More file actions
86 lines (75 loc) · 1.96 KB
/
Copy pathHelper_Logging.ps1
File metadata and controls
86 lines (75 loc) · 1.96 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Helper functions for logging
#
# Find us here:
# - https://www.improsec.com
# - https://github.com/improsec
# - https://twitter.com/improsec
# - https://www.facebook.com/improsec
# ================ #
# FUNCTIONS =====> #
# ================ #
function Log-Specific {
param (
# full path to the destination file for logging
[Parameter(Mandatory=$true)]
[string]
$filename,
# string to output to the log-file
[Parameter(Mandatory=$true)]
[string]
$string,
# information-type of the output string
[ValidateSet("info", "data", "fail")]
[string]
$type,
# whether to log with time-stamp or not
[switch]
$timestamp
)
if ($PSBoundParameters.ContainsKey('type')) {
if ($timestamp) {
$now = Get-Date -Format dd.MM.yyyy-HH:mm:ss
Add-content -Path $filename -Value "$now`t$type`t$string"
} else {
Add-content -Path $filename -Value "$type`t$string"
}
} else {
if ($timestamp) {
$now = Get-Date -Format dd.MM.yyyy-HH:mm:ss
Add-content -Path $filename -Value "$now`t$string"
} else {
Add-content -Path $filename -Value "$string"
}
}
}
function Log-Automatic {
param (
# string to output to the log-file
[Parameter(Mandatory=$true)]
[string]
$string,
# information-type of the output string
[ValidateSet("info", "data", "fail")]
[string]
$type,
# whether to log with time-stamp or not
[switch]
$timestamp
)
Write-Host -Object $string
if ($write_to_log_file) {
if ($PSBoundParameters.ContainsKey('type')) {
if ($timestamp) {
Log-Specific -filename $log_filename -string $string -type $type -timestamp
} else {
Log-Specific -filename $log_filename -string $string -type $type
}
} else {
if ($timestamp) {
Log-Specific -filename $log_filename -string $string -timestamp
} else {
Log-Specific -filename $log_filename -string $string
}
}
}
}