-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
46 lines (40 loc) · 1.11 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
package main
import (
"bytes"
"github.com/Miuzarte/ANSIFmt"
log "github.com/sirupsen/logrus"
)
type LogFormat struct{}
func (f *LogFormat) Format(entry *log.Entry) ([]byte, error) {
buf := new(bytes.Buffer)
buf.WriteString(logLevelBanner[entry.Level])
buf.WriteString(entry.Time.Format("[01/02|15:04:05] "))
buf.WriteString(entry.Message)
buf.WriteString("\n")
return buf.Bytes(), nil
}
var (
logLevelBanner = map[log.Level]string{
log.TraceLevel: ANSIFmt.New().
Set(ANSIFmt.Fore.BrightBlue).
Sprint("[TRAC]"),
log.DebugLevel: ANSIFmt.New().
Set(ANSIFmt.Fore.BrightGreen).
Sprint("[DEBU]"),
log.InfoLevel: ANSIFmt.New().
Set(ANSIFmt.Fore.BrightWhite).
Sprint("[INFO]"),
log.WarnLevel: ANSIFmt.New().
Set(ANSIFmt.Fore.BrightYellow).
Sprint("[WARN]"),
log.ErrorLevel: ANSIFmt.New().
Set(ANSIFmt.Fore.BrightRed).
Sprint("[ERRO]"),
log.FatalLevel: ANSIFmt.New().
Set(ANSIFmt.Fore.BrightRed, ANSIFmt.Style.SlowBlink).
Sprint("[FATA]"),
log.PanicLevel: ANSIFmt.New().
Set(ANSIFmt.Fore.BrightRed, ANSIFmt.Style.SlowBlink, ANSIFmt.Style.Invert).
Sprint("[PANI]"),
}
)