forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
49 lines (42 loc) · 1.07 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
package log
import (
"github.com/sirupsen/logrus"
)
// Logger is the main struct that any athens
// internal service should use to communicate things.
type Logger struct {
*logrus.Logger
}
// New constructs a new logger based on the
// environment and the cloud platform it is
// running on. TODO: take cloud arg and env
// to construct the correct JSON formatter.
func New(cloudProvider string, level logrus.Level) *Logger {
l := logrus.New()
switch cloudProvider {
case "GCP":
l.Formatter = getGCPFormatter()
case "none":
l.Formatter = getDevFormatter()
default:
l.Formatter = getDefaultFormatter()
}
l.Level = level
return &Logger{Logger: l}
}
// SystemErr Entry implementation.
func (l *Logger) SystemErr(err error) {
e := &entry{Entry: logrus.NewEntry(l.Logger)}
e.SystemErr(err)
}
// WithFields Entry implementation.
func (l *Logger) WithFields(fields map[string]interface{}) Entry {
e := l.Logger.WithFields(fields)
return &entry{e}
}
// NoOpLogger provides a Logger that does nothing
func NoOpLogger() *Logger {
return &Logger{
Logger: &logrus.Logger{},
}
}