1
0
mirror of https://github.com/labstack/echo.git synced 2025-01-12 01:22:21 +02:00

fix #1260 change middleware.Logger's default output (#1336)

* fix TestLoggerIPAddress reverse assertion

* change middleware.Logger default output

* remove nil field declaration
This commit is contained in:
nattawitc 2019-07-18 11:34:31 +07:00 committed by Vishal Rana
parent 405b221ad4
commit 8cfaf50b8f
2 changed files with 7 additions and 5 deletions

View File

@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"io"
"os"
"strconv"
"strings"
"sync"
@ -74,7 +73,6 @@ var (
`"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` +
`,"bytes_in":${bytes_in},"bytes_out":${bytes_out}}` + "\n",
CustomTimeFormat: "2006-01-02 15:04:05.00000",
Output: os.Stdout,
colorer: color.New(),
}
)
@ -214,6 +212,10 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
return
}
if config.Output == nil {
_, err = c.Logger().Output().Write(buf.Bytes())
return
}
_, err = config.Output.Write(buf.Bytes())
return
}

View File

@ -70,18 +70,18 @@ func TestLoggerIPAddress(t *testing.T) {
// With X-Real-IP
req.Header.Add(echo.HeaderXRealIP, ip)
h(c)
assert.Contains(t, ip, buf.String())
assert.Contains(t, buf.String(), ip)
// With X-Forwarded-For
buf.Reset()
req.Header.Del(echo.HeaderXRealIP)
req.Header.Add(echo.HeaderXForwardedFor, ip)
h(c)
assert.Contains(t, ip, buf.String())
assert.Contains(t, buf.String(), ip)
buf.Reset()
h(c)
assert.Contains(t, ip, buf.String())
assert.Contains(t, buf.String(), ip)
}
func TestLoggerTemplate(t *testing.T) {