-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconvert.go
51 lines (46 loc) · 998 Bytes
/
convert.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
package logrus4logr
import (
"github.com/wiggin77/logr"
"github.com/sirupsen/logrus"
)
func convertLogRec(rec *logr.LogRec, rus *logrus.Logger) *logrus.Entry {
entry := &logrus.Entry{
Logger: rus,
Data: convertFields(rec.Fields()),
Time: rec.Time(),
Level: convertLevel(rec.Level()),
//Caller: *runtime.Frame
Message: rec.Msg(),
//Buffer *bytes.Buffer
//Context context.Context
//err string
}
return entry
}
func convertLevel(lvl logr.Level) logrus.Level {
switch lvl {
case logr.Panic:
return logrus.PanicLevel
case logr.Fatal:
return logrus.FatalLevel
case logr.Error:
return logrus.ErrorLevel
case logr.Warn:
return logrus.WarnLevel
case logr.Info:
return logrus.InfoLevel
case logr.Debug:
return logrus.DebugLevel
case logr.Trace:
return logrus.TraceLevel
default:
return logrus.InfoLevel
}
}
func convertFields(flds logr.Fields) logrus.Fields {
f := make(logrus.Fields, len(flds))
for k, v := range flds {
f[k] = v
}
return f
}