-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
67 lines (52 loc) · 1.34 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
package hatchcert
import (
"bytes"
"fmt"
"os"
"github.com/go-acme/lego/v4/log"
)
type LegoOutput struct {
Previous log.StdLogger
Output bytes.Buffer
}
func (l *LegoOutput) Emit() {
os.Stderr.Write(l.Output.Bytes())
}
func (l *LegoOutput) write(pfx, msg string) {
l.Output.Write([]byte(pfx + msg + "\n"))
}
func (l *LegoOutput) Fatal(args ...interface{}) {
l.write("fatal: ", fmt.Sprint(args...))
}
func (l *LegoOutput) Fatalln(args ...interface{}) {
l.write("fatal: ", fmt.Sprintln(args...))
}
func (l *LegoOutput) Fatalf(format string, args ...interface{}) {
l.write("fatal: ", fmt.Sprintf(format, args...))
}
func (l *LegoOutput) Print(args ...interface{}) {
l.write("", fmt.Sprint(args...))
}
func (l *LegoOutput) Println(args ...interface{}) {
l.write("", fmt.Sprintln(args...))
}
func (l *LegoOutput) Printf(format string, args ...interface{}) {
l.write("", fmt.Sprintf(format, args...))
}
func (l *LegoOutput) Warnf(format string, args ...interface{}) {
l.write("warning: ", fmt.Sprintf(format, args...))
}
func (l *LegoOutput) Infof(format string, args ...interface{}) {
l.write("info: ", fmt.Sprintf(format, args...))
}
func (l *LegoOutput) Restore() {
if l.Previous != nil {
log.Logger = l.Previous
l.Previous = nil
}
}
func InterceptOutput() *LegoOutput {
o := &LegoOutput{Previous: log.Logger}
log.Logger = o
return o
}