-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
59 lines (47 loc) · 1.47 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
package usts
import (
"log"
"os"
)
//‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾
// Logger interface
//_______________________________________________________________________
// Logger interface is to abstract the logging from Usts. Gives control to
// the USTS users, choice of the logger.
type Logger interface {
Infof(format string, v ...interface{})
Errorf(format string, v ...interface{})
Warnf(format string, v ...interface{})
Debugf(format string, v ...interface{})
Tracef(format string, v ...interface{})
}
func createLogger() *logger {
l := &logger{l: log.New(os.Stderr, "", log.Ldate|log.Ltime)}
return l
}
var _ Logger = (*logger)(nil)
type logger struct {
l *log.Logger
}
func (l *logger) Errorf(format string, v ...interface{}) {
l.output("USTS ERROR: "+format, v...)
}
func (l *logger) Warnf(format string, v ...interface{}) {
l.output("USTS WARN: "+format, v...)
}
func (l *logger) Infof(format string, v ...interface{}) {
l.output("USTS INFO: "+format, v...)
}
func (l *logger) Debugf(format string, v ...interface{}) {
l.output("USTS DEBUG: "+format, v...)
}
func (l *logger) Tracef(format string, v ...interface{}) {
l.output("USTS TRACE: "+format, v...)
}
func (l *logger) output(format string, v ...interface{}) {
if len(v) == 0 {
l.l.Print(format)
return
}
l.l.Printf(format, v...)
}