-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlog.go
56 lines (44 loc) · 936 Bytes
/
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
package log
import (
"fmt"
"io"
"os"
)
type Level int
const (
FATAL Level = iota
INFO
)
type Logger struct {
Level Level
out io.Writer
}
var Default = New(FATAL, os.Stderr)
func New(level Level, out io.Writer) *Logger {
return &Logger{
Level: level,
out: out,
}
}
func (l *Logger) Log(level Level, format string, a ...interface{}) (int, error) {
if l.Level < level {
return 0, nil
}
return fmt.Fprintf(l.out, format+"\n", a...)
}
func Log(level Level, format string, a ...interface{}) (int, error) {
return Default.Log(level, format, a...)
}
func (l *Logger) Fatal(s string, a ...interface{}) {
l.Log(FATAL, "[FATAL] "+s, a...)
os.Exit(2)
}
func Fatal(s string, a ...interface{}) {
Default.Fatal(s, a...)
}
func (l *Logger) Info(s string, a ...interface{}) (int, error) {
return l.Log(INFO, "[INFO] "+s, a...)
}
func Info(s string, a ...interface{}) (int, error) {
return Default.Info(s, a...)
}