forked from sandalwing/echo-logrusmiddleware
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbridge.go
103 lines (85 loc) · 2.17 KB
/
bridge.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package logrusmiddleware
import (
"io"
"github.com/labstack/gommon/log"
"github.com/sirupsen/logrus"
)
// Logger bridges the echo.Logger interface to use sirupsen.Logrus as the implementation
type Logger struct {
*logrus.Logger
}
//Output gets the output
func (l Logger) Output() io.Writer {
return l.Logger.Out
}
//SetOutput sets the output
func (l Logger) SetOutput(w io.Writer) {
l.Logger.Out = w
}
// Prefix is not supported and returns an empty string
func (l Logger) Prefix() string {
return ""
}
// SetPrefix is not supported and is a NOOP
func (l Logger) SetPrefix(s string) {}
// Level gets the current logging level
func (l Logger) Level() log.Lvl {
switch l.Logger.Level {
case logrus.DebugLevel:
return log.DEBUG
case logrus.WarnLevel:
return log.WARN
case logrus.ErrorLevel:
return log.ERROR
case logrus.InfoLevel:
return log.INFO
default:
l.Logger.Panic("Invalid level")
}
return log.OFF
}
// SetLevel sets the logging level
func (l Logger) SetLevel(lvl log.Lvl) {
switch lvl {
case log.DEBUG:
l.Logger.SetLevel(logrus.DebugLevel)
case log.WARN:
l.Logger.SetLevel(logrus.WarnLevel)
case log.ERROR:
l.Logger.SetLevel(logrus.ErrorLevel)
case log.INFO:
l.Logger.SetLevel(logrus.InfoLevel)
default:
l.Logger.Panic("Invalid level")
}
}
// SetHeader is not supported and is a NOOP
func (l Logger) SetHeader(header string) {}
//Printj prints with fields
func (l Logger) Printj(j log.JSON) {
l.Logger.WithFields(logrus.Fields(j)).Print()
}
//Debugj logs with fields at debug
func (l Logger) Debugj(j log.JSON) {
l.Logger.WithFields(logrus.Fields(j)).Debug()
}
//Infoj logs with fields at info
func (l Logger) Infoj(j log.JSON) {
l.Logger.WithFields(logrus.Fields(j)).Info()
}
//Warnj logs with fields at warn
func (l Logger) Warnj(j log.JSON) {
l.Logger.WithFields(logrus.Fields(j)).Warn()
}
//Errorj logs with fields at error
func (l Logger) Errorj(j log.JSON) {
l.Logger.WithFields(logrus.Fields(j)).Error()
}
//Fatalj logs with fields at fatal
func (l Logger) Fatalj(j log.JSON) {
l.Logger.WithFields(logrus.Fields(j)).Fatal()
}
//Panicj logs with fields at panic
func (l Logger) Panicj(j log.JSON) {
l.Logger.WithFields(logrus.Fields(j)).Panic()
}