-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlogger.go
More file actions
89 lines (67 loc) · 1.75 KB
/
logger.go
File metadata and controls
89 lines (67 loc) · 1.75 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package gozap
import "errors"
// A global variable so that log functions can be directly accessed
var log Logger
//Fields Type to pass when we want to call WithFields for structured logging
type Fields map[string]interface{}
const (
//for verbose logging
Debug = "debug"
Info = "info"
Warn = "warn"
Error = "error"
//Fatal is for logging fatal messages. The sytem shutsdown after logging the message.
Fatal = "fatal"
)
const (
InstanceZapLogger int = iota
)
var (
errInvalidLoggerInstance = errors.New("Invalid logger instance")
)
type Logger interface {
Debugf(format string, args ...interface{})
Infof(format string, args ...interface{})
Warnf(format string, args ...interface{})
Errorf(format string, args ...interface{})
Fatalf(format string, args ...interface{})
Panicf(format string, args ...interface{})
}
// Configuration stores the config for the logger
type Configuration struct {
EnableConsole bool
ConsoleJSONFormat bool
ConsoleLevel string
EnableFile bool
FileJSONFormat bool
FileLevel string
FileLocation string
}
//NewLogger returns an instance of logger
func NewLogger(config Configuration) error {
logger, err := newZapLogger(config)
if err != nil {
return err
}
log = logger
return nil
}
//interface impl
func Debugf(format string, args ...interface{}) {
log.Debugf(format, args...)
}
func Infof(format string, args ...interface{}) {
log.Infof(format, args...)
}
func Warnf(format string, args ...interface{}) {
log.Warnf(format, args...)
}
func Errorf(format string, args ...interface{}) {
log.Errorf(format, args...)
}
func Fatalf(format string, args ...interface{}) {
log.Fatalf(format, args...)
}
func Panicf(format string, args ...interface{}) {
log.Panicf(format, args...)
}