forked from jsimonetti/go-artnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
57 lines (44 loc) · 1.25 KB
/
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
54
55
56
57
package artnet
import (
"os"
"github.com/sirupsen/logrus"
)
// Fields are a representation of formatted log fields
type Fields map[string]interface{}
// Logger is the interface for a logger
type Logger interface {
logrus.StdLogger
With(fields Fields) *logger
}
type logger struct {
*logrus.Entry
}
// NewLogger returns a Logger based on logrus
func NewDefaultLogger() Logger {
log := &struct {
*logrus.Logger
}{
Logger: logrus.New(),
}
customFormatter := new(logrus.TextFormatter)
customFormatter.TimestampFormat = "2006-01-02 15:04:05.0000"
customFormatter.DisableColors = true
customFormatter.FullTimestamp = true
log.Formatter = customFormatter
// Output to stdout instead of the default stderr
// Can be any io.Writer, see below for File example
log.Out = os.Stdout
// Only log the debug severity or above.
log.Level = logrus.DebugLevel
// Disable concurrency mutex as we use Stdout
log.SetNoLock()
return &logger{Entry: log.WithFields(nil)}
}
// NewLogger creates a new logger from given logrus logger
func NewLogger(log *logrus.Entry) Logger {
return &logger{log}
}
// With will add the fields to the formatted log entry
func (l *logger) With(fields Fields) *logger {
return &logger{Entry: l.WithFields(logrus.Fields(fields))}
}