forked from pressly/goose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
45 lines (35 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
package goose
import (
std "log"
)
var log Logger = &stdLogger{}
// Logger is standard logger interface
type Logger interface {
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
Print(v ...interface{})
Println(v ...interface{})
Printf(format string, v ...interface{})
}
// SetLogger sets the logger for package output
func SetLogger(l Logger) {
log = l
}
// stdLogger is a default logger that outputs to a stdlib's log.std logger.
type stdLogger struct{}
func (*stdLogger) Fatal(v ...interface{}) { std.Fatal(v...) }
func (*stdLogger) Fatalf(format string, v ...interface{}) { std.Fatalf(format, v...) }
func (*stdLogger) Print(v ...interface{}) { std.Print(v...) }
func (*stdLogger) Println(v ...interface{}) { std.Println(v...) }
func (*stdLogger) Printf(format string, v ...interface{}) { std.Printf(format, v...) }
// NopLogger returns a logger that discards all logged output.
func NopLogger() Logger {
return &nopLogger{}
}
type nopLogger struct{}
var _ Logger = (*nopLogger)(nil)
func (*nopLogger) Fatal(v ...interface{}) {}
func (*nopLogger) Fatalf(format string, v ...interface{}) {}
func (*nopLogger) Print(v ...interface{}) {}
func (*nopLogger) Println(v ...interface{}) {}
func (*nopLogger) Printf(format string, v ...interface{}) {}