Skip to content

Commit f4088cf

Browse files
committed
Added JSON logging
Signed-off-by: Vishal Rana <[email protected]>
1 parent 6783909 commit f4088cf

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

echo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ func (e *Echo) SetLogOutput(w io.Writer) {
267267
e.logger.SetOutput(w)
268268
}
269269

270-
// SetLogLevel sets the log level for the logger. Default value `3` (ERROR).
271-
func (e *Echo) SetLogLevel(l uint8) {
270+
// SetLogLevel sets the log level for the logger. Default value ERROR.
271+
func (e *Echo) SetLogLevel(l glog.Lvl) {
272272
e.logger.SetLevel(l)
273273
}
274274

glide.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

log/logger.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
11
package log
22

3-
import "io"
3+
import (
4+
"io"
5+
6+
"github.com/labstack/gommon/log"
7+
)
48

59
type (
610
// Logger defines the logging interface.
711
Logger interface {
812
SetOutput(io.Writer)
9-
SetLevel(uint8)
13+
SetLevel(log.Lvl)
1014
Print(...interface{})
1115
Printf(string, ...interface{})
16+
Printj(log.JSON)
1217
Debug(...interface{})
1318
Debugf(string, ...interface{})
19+
Debugj(log.JSON)
1420
Info(...interface{})
1521
Infof(string, ...interface{})
22+
Infoj(log.JSON)
1623
Warn(...interface{})
1724
Warnf(string, ...interface{})
25+
Warnj(log.JSON)
1826
Error(...interface{})
1927
Errorf(string, ...interface{})
28+
Errorj(log.JSON)
2029
Fatal(...interface{})
30+
Fatalj(log.JSON)
2131
Fatalf(string, ...interface{})
2232
}
2333
)

middleware/logger.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package middleware
22

33
import (
44
"bytes"
5-
"fmt"
65
"io"
76
"net"
87
"os"
@@ -158,9 +157,8 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
158157
return w.Write([]byte(b))
159158
case "tx_bytes":
160159
return w.Write([]byte(strconv.FormatInt(res.Size(), 10)))
161-
default:
162-
return w.Write([]byte(fmt.Sprintf("[unknown tag %s]", tag)))
163160
}
161+
return 0, nil
164162
})
165163
if err == nil {
166164
config.Output.Write(buf.Bytes())

0 commit comments

Comments
 (0)