-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
47 lines (43 loc) · 996 Bytes
/
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
package cardcaldav
import (
"github.com/charmbracelet/log"
"github.com/rs/zerolog"
log0 "github.com/rs/zerolog/log"
"strings"
)
type zeroToCharmLogger struct{ logger *log.Logger }
func (z *zeroToCharmLogger) Write(p []byte) (n int, err error) {
s := string(p)
if len(s) <= 3 {
return len(p), nil
}
inLevel := s[:3]
var level log.Level
switch inLevel {
case "TRC", "DBG":
level = log.DebugLevel
case "INF":
level = log.InfoLevel
case "WRN":
level = log.WarnLevel
case "ERR":
level = log.ErrorLevel
case "FTL", "PNC":
level = log.FatalLevel
}
z.logger.Helper()
translator := z.logger.With()
translator.SetCallerFormatter(func(s string, i int, s2 string) string {
return "tokidoki internal"
})
translator.Log(level, strings.TrimSpace(s[4:]))
return len(p), nil
}
func SetupLogger(logger *log.Logger) {
log0.Logger = log0.Output(zerolog.ConsoleWriter{
Out: &zeroToCharmLogger{logger},
FormatTimestamp: func(i interface{}) string {
return ""
},
})
}