forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
74 lines (57 loc) · 1.48 KB
/
log.go
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
package log
import (
"io"
"regexp"
)
const redactedText = "<REDACTED>"
var (
logger = NewFmtMachineLogger()
// (?s) enables '.' to match '\n' -- see https://golang.org/pkg/regexp/syntax/
certRegex = regexp.MustCompile("(?s)-----BEGIN CERTIFICATE-----.*-----END CERTIFICATE-----")
keyRegex = regexp.MustCompile("(?s)-----BEGIN RSA PRIVATE KEY-----.*-----END RSA PRIVATE KEY-----")
)
func stripSecrets(original []string) []string {
stripped := []string{}
for _, line := range original {
line = certRegex.ReplaceAllString(line, redactedText)
line = keyRegex.ReplaceAllString(line, redactedText)
stripped = append(stripped, line)
}
return stripped
}
func Debug(args ...interface{}) {
logger.Debug(args...)
}
func Debugf(fmtString string, args ...interface{}) {
logger.Debugf(fmtString, args...)
}
func Error(args ...interface{}) {
logger.Error(args...)
}
func Errorf(fmtString string, args ...interface{}) {
logger.Errorf(fmtString, args...)
}
func Info(args ...interface{}) {
logger.Info(args...)
}
func Infof(fmtString string, args ...interface{}) {
logger.Infof(fmtString, args...)
}
func Warn(args ...interface{}) {
logger.Warn(args...)
}
func Warnf(fmtString string, args ...interface{}) {
logger.Warnf(fmtString, args...)
}
func SetDebug(debug bool) {
logger.SetDebug(debug)
}
func SetOutWriter(out io.Writer) {
logger.SetOutWriter(out)
}
func SetErrWriter(err io.Writer) {
logger.SetErrWriter(err)
}
func History() []string {
return stripSecrets(logger.History())
}