-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
53 lines (43 loc) · 926 Bytes
/
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
package main
import (
"fmt"
"io"
"io/ioutil"
"os"
"time"
)
type logger struct {
infoOutput io.Writer
errOutput io.Writer
}
func simpleLogger(quiet bool) logger {
var errOut, infoOut io.Writer
if quiet {
errOut, infoOut = ioutil.Discard, ioutil.Discard
} else {
errOut, infoOut = os.Stderr, os.Stdout
}
return logger{
infoOutput: infoOut,
errOutput: errOut,
}
}
func (l logger) Errorf(format string, in ...interface{}) {
l.Error(fmt.Sprintf(format, in...))
}
func (l logger) Error(msg string) {
l.print(l.errOutput, msg)
}
func (l logger) Critical(msg string) {
l.print(l.errOutput, msg)
os.Exit(1)
}
func (l logger) Infof(format string, in ...interface{}) {
l.Info(fmt.Sprintf(format, in...))
}
func (l logger) Info(msg string) {
l.print(l.infoOutput, msg)
}
func (l logger) print(writer io.Writer, msg string) {
fmt.Fprintf(writer, "[%s] %s\n", time.Now().Format(time.RFC3339), msg)
}