-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
39 lines (32 loc) · 996 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
package ripcord
import (
"io"
log "github.com/Sirupsen/logrus"
)
// NewLogger returns a pointer to a new logrus logger with all
// sensible defaults configured.
func NewLogger(out io.Writer, level log.Level) (logger *log.Logger) {
logger = log.New()
logger.Level = level
logger.Out = out
logger.Formatter = UTCFormatter{&log.TextFormatter{
// always using the full timestamp formatter because the default
// number-based timestamp formatter makes distributed logging
// impossible.
FullTimestamp: true,
// always disabling console colours because they don't make for
// easy reading in terminals that don't support it.
DisableColors: true,
}}
return
}
// UTCFormatter formats logrus timestamps in UTC format
// rather than the default local format.
type UTCFormatter struct {
log.Formatter
}
// Format takes a local timestamp and converts it to UTC.
func (u UTCFormatter) Format(e *log.Entry) ([]byte, error) {
e.Time = e.Time.UTC()
return u.Formatter.Format(e)
}