forked from docker/machine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fmt_machine_logger.go
84 lines (69 loc) · 1.91 KB
/
fmt_machine_logger.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
75
76
77
78
79
80
81
82
83
84
package log
import (
"fmt"
"io"
"os"
)
type FmtMachineLogger struct {
outWriter io.Writer
errWriter io.Writer
debug bool
history *HistoryRecorder
}
// NewFmtMachineLogger creates a MachineLogger implementation used by the drivers
func NewFmtMachineLogger() MachineLogger {
return &FmtMachineLogger{
outWriter: os.Stdout,
errWriter: os.Stderr,
debug: false,
history: NewHistoryRecorder(),
}
}
func (ml *FmtMachineLogger) SetDebug(debug bool) {
ml.debug = debug
}
func (ml *FmtMachineLogger) SetOutWriter(out io.Writer) {
ml.outWriter = out
}
func (ml *FmtMachineLogger) SetErrWriter(err io.Writer) {
ml.errWriter = err
}
func (ml *FmtMachineLogger) Debug(args ...interface{}) {
ml.history.Record(args...)
if ml.debug {
fmt.Fprintln(ml.errWriter, args...)
}
}
func (ml *FmtMachineLogger) Debugf(fmtString string, args ...interface{}) {
ml.history.Recordf(fmtString, args...)
if ml.debug {
fmt.Fprintf(ml.errWriter, fmtString+"\n", args...)
}
}
func (ml *FmtMachineLogger) Error(args ...interface{}) {
ml.history.Record(args...)
fmt.Fprintln(ml.errWriter, args...)
}
func (ml *FmtMachineLogger) Errorf(fmtString string, args ...interface{}) {
ml.history.Recordf(fmtString, args...)
fmt.Fprintf(ml.errWriter, fmtString+"\n", args...)
}
func (ml *FmtMachineLogger) Info(args ...interface{}) {
ml.history.Record(args...)
fmt.Fprintln(ml.outWriter, args...)
}
func (ml *FmtMachineLogger) Infof(fmtString string, args ...interface{}) {
ml.history.Recordf(fmtString, args...)
fmt.Fprintf(ml.outWriter, fmtString+"\n", args...)
}
func (ml *FmtMachineLogger) Warn(args ...interface{}) {
ml.history.Record(args...)
fmt.Fprintln(ml.outWriter, args...)
}
func (ml *FmtMachineLogger) Warnf(fmtString string, args ...interface{}) {
ml.history.Recordf(fmtString, args...)
fmt.Fprintf(ml.outWriter, fmtString+"\n", args...)
}
func (ml *FmtMachineLogger) History() []string {
return ml.history.records
}