1
0
mirror of https://github.com/labstack/echo.git synced 2025-04-25 12:24:55 +02:00

Added JSON logging

Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
Vishal Rana 2016-06-08 17:16:03 -07:00
parent 6783909459
commit f4088cf594
4 changed files with 20 additions and 12 deletions

View File

@ -267,8 +267,8 @@ func (e *Echo) SetLogOutput(w io.Writer) {
e.logger.SetOutput(w) e.logger.SetOutput(w)
} }
// SetLogLevel sets the log level for the logger. Default value `3` (ERROR). // SetLogLevel sets the log level for the logger. Default value ERROR.
func (e *Echo) SetLogLevel(l uint8) { func (e *Echo) SetLogLevel(l glog.Lvl) {
e.logger.SetLevel(l) e.logger.SetLevel(l)
} }

10
glide.lock generated
View File

@ -1,12 +1,12 @@
hash: 21820434709470e49c64df0f854d3352088ca664d193e29bc6cd434518c27a7c hash: 21820434709470e49c64df0f854d3352088ca664d193e29bc6cd434518c27a7c
updated: 2016-06-06T13:46:58.552123246-07:00 updated: 2016-06-08T17:12:40.290079497-07:00
imports: imports:
- name: github.com/davecgh/go-spew - name: github.com/davecgh/go-spew
version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d version: 5215b55f46b2b919f50a1df0eaa5886afe4e3b3d
subpackages: subpackages:
- spew - spew
- name: github.com/dgrijalva/jwt-go - name: github.com/dgrijalva/jwt-go
version: 9b486c879bab3fde556ce8c27d9a2bb05d5b2c60 version: c04502f106d7c5b3fae17c5da49a1bbdd3006b3c
- name: github.com/klauspost/compress - name: github.com/klauspost/compress
version: 14eb9c4951195779ecfbec34431a976de7335b0a version: 14eb9c4951195779ecfbec34431a976de7335b0a
subpackages: subpackages:
@ -18,7 +18,7 @@ imports:
- name: github.com/klauspost/crc32 - name: github.com/klauspost/crc32
version: 19b0b332c9e4516a6370a0456e6182c3b5036720 version: 19b0b332c9e4516a6370a0456e6182c3b5036720
- name: github.com/labstack/gommon - name: github.com/labstack/gommon
version: c21cbdaff511c8f7c27dab37216552d8e7ea7bde version: 7949d308ed2888a634cf124a2f0755e0867b9e1f
subpackages: subpackages:
- color - color
- log - log
@ -36,11 +36,11 @@ imports:
subpackages: subpackages:
- assert - assert
- name: github.com/valyala/fasthttp - name: github.com/valyala/fasthttp
version: 3c5ba2c98d622df52926a4d17be18a6728ccaf1c version: 8f05edbec9fb5b0c7a4012ee746035a82e3e8bfb
- name: github.com/valyala/fasttemplate - name: github.com/valyala/fasttemplate
version: 3b874956e03f1636d171bda64b130f9135f42cff version: 3b874956e03f1636d171bda64b130f9135f42cff
- name: golang.org/x/net - name: golang.org/x/net
version: c4c3ea71919de159c9e246d7be66deb7f0a39a58 version: 313cf39d4ac368181bce6960ac9be9e7cee67e68
subpackages: subpackages:
- context - context
- websocket - websocket

View File

@ -1,23 +1,33 @@
package log package log
import "io" import (
"io"
"github.com/labstack/gommon/log"
)
type ( type (
// Logger defines the logging interface. // Logger defines the logging interface.
Logger interface { Logger interface {
SetOutput(io.Writer) SetOutput(io.Writer)
SetLevel(uint8) SetLevel(log.Lvl)
Print(...interface{}) Print(...interface{})
Printf(string, ...interface{}) Printf(string, ...interface{})
Printj(log.JSON)
Debug(...interface{}) Debug(...interface{})
Debugf(string, ...interface{}) Debugf(string, ...interface{})
Debugj(log.JSON)
Info(...interface{}) Info(...interface{})
Infof(string, ...interface{}) Infof(string, ...interface{})
Infoj(log.JSON)
Warn(...interface{}) Warn(...interface{})
Warnf(string, ...interface{}) Warnf(string, ...interface{})
Warnj(log.JSON)
Error(...interface{}) Error(...interface{})
Errorf(string, ...interface{}) Errorf(string, ...interface{})
Errorj(log.JSON)
Fatal(...interface{}) Fatal(...interface{})
Fatalj(log.JSON)
Fatalf(string, ...interface{}) Fatalf(string, ...interface{})
} }
) )

View File

@ -2,7 +2,6 @@ package middleware
import ( import (
"bytes" "bytes"
"fmt"
"io" "io"
"net" "net"
"os" "os"
@ -158,9 +157,8 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
return w.Write([]byte(b)) return w.Write([]byte(b))
case "tx_bytes": case "tx_bytes":
return w.Write([]byte(strconv.FormatInt(res.Size(), 10))) return w.Write([]byte(strconv.FormatInt(res.Size(), 10)))
default:
return w.Write([]byte(fmt.Sprintf("[unknown tag %s]", tag)))
} }
return 0, nil
}) })
if err == nil { if err == nil {
config.Output.Write(buf.Bytes()) config.Output.Write(buf.Bytes())