mirror of
https://github.com/labstack/echo.git
synced 2025-04-21 12:17:04 +02:00
* fix TestLoggerIPAddress reverse assertion * change middleware.Logger default output * remove nil field declaration
This commit is contained in:
parent
405b221ad4
commit
8cfaf50b8f
@ -4,7 +4,6 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -74,7 +73,6 @@ var (
|
|||||||
`"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` +
|
`"status":${status},"error":"${error}","latency":${latency},"latency_human":"${latency_human}"` +
|
||||||
`,"bytes_in":${bytes_in},"bytes_out":${bytes_out}}` + "\n",
|
`,"bytes_in":${bytes_in},"bytes_out":${bytes_out}}` + "\n",
|
||||||
CustomTimeFormat: "2006-01-02 15:04:05.00000",
|
CustomTimeFormat: "2006-01-02 15:04:05.00000",
|
||||||
Output: os.Stdout,
|
|
||||||
colorer: color.New(),
|
colorer: color.New(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -214,6 +212,10 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Output == nil {
|
||||||
|
_, err = c.Logger().Output().Write(buf.Bytes())
|
||||||
|
return
|
||||||
|
}
|
||||||
_, err = config.Output.Write(buf.Bytes())
|
_, err = config.Output.Write(buf.Bytes())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -70,18 +70,18 @@ func TestLoggerIPAddress(t *testing.T) {
|
|||||||
// With X-Real-IP
|
// With X-Real-IP
|
||||||
req.Header.Add(echo.HeaderXRealIP, ip)
|
req.Header.Add(echo.HeaderXRealIP, ip)
|
||||||
h(c)
|
h(c)
|
||||||
assert.Contains(t, ip, buf.String())
|
assert.Contains(t, buf.String(), ip)
|
||||||
|
|
||||||
// With X-Forwarded-For
|
// With X-Forwarded-For
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
req.Header.Del(echo.HeaderXRealIP)
|
req.Header.Del(echo.HeaderXRealIP)
|
||||||
req.Header.Add(echo.HeaderXForwardedFor, ip)
|
req.Header.Add(echo.HeaderXForwardedFor, ip)
|
||||||
h(c)
|
h(c)
|
||||||
assert.Contains(t, ip, buf.String())
|
assert.Contains(t, buf.String(), ip)
|
||||||
|
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
h(c)
|
h(c)
|
||||||
assert.Contains(t, ip, buf.String())
|
assert.Contains(t, buf.String(), ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoggerTemplate(t *testing.T) {
|
func TestLoggerTemplate(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user