-
Notifications
You must be signed in to change notification settings - Fork 15
/
logger.go
51 lines (40 loc) · 1.25 KB
/
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
package flagsmith
import (
"log"
"os"
)
// Logger is the interface used for logging by flagsmith client. This interface defines the methods
// that a logger implementation must implement. It is used to abstract logging and
// enable clients to use any logger implementation they want.
type Logger interface {
// Errorf logs an error message with the given format and arguments.
Errorf(format string, v ...interface{})
// Warnf logs a warning message with the given format and arguments.
Warnf(format string, v ...interface{})
// Debugf logs a debug message with the given format and arguments.
Debugf(format string, v ...interface{})
}
func createLogger() *logger {
l := &logger{l: log.New(os.Stderr, "", log.Ldate|log.Lmicroseconds)}
return l
}
var _ Logger = (*logger)(nil)
type logger struct {
l *log.Logger
}
func (l *logger) Errorf(format string, v ...interface{}) {
l.output("ERROR FLAGSMITH: "+format, v...)
}
func (l *logger) Warnf(format string, v ...interface{}) {
l.output("WARN FLAGSMITH: "+format, v...)
}
func (l *logger) Debugf(format string, v ...interface{}) {
l.output("DEBUG FLAGSMITH: "+format, v...)
}
func (l *logger) output(format string, v ...interface{}) {
if len(v) == 0 {
l.l.Print(format)
return
}
l.l.Printf(format, v...)
}