mirror of
https://github.com/labstack/echo.git
synced 2024-12-24 20:14:31 +02:00
parent
533d7a8dc1
commit
1827916e76
@ -183,6 +183,11 @@ func LoggerWithConfig(config LoggerConfig) echo.MiddlewareFunc {
|
||||
return buf.Write([]byte(c.QueryParam(tag[6:])))
|
||||
case strings.HasPrefix(tag, "form:"):
|
||||
return buf.Write([]byte(c.FormValue(tag[5:])))
|
||||
case strings.HasPrefix(tag, "cookie:"):
|
||||
cookie, err := c.Cookie(tag[7:])
|
||||
if err == nil {
|
||||
return buf.Write([]byte(cookie.Value))
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0, nil
|
||||
|
@ -90,7 +90,7 @@ func TestLoggerTemplate(t *testing.T) {
|
||||
`"method":"${method}","uri":"${uri}","status":${status}, "latency":${latency},` +
|
||||
`"latency_human":"${latency_human}","bytes_in":${bytes_in}, "path":"${path}", "referer":"${referer}",` +
|
||||
`"bytes_out":${bytes_out},"ch":"${header:X-Custom-Header}",` +
|
||||
`"us":"${query:username}", "cf":"${form:username}"}` + "\n",
|
||||
`"us":"${query:username}", "cf":"${form:username}", "session":"${cookie:session}"}` + "\n",
|
||||
Output: buf,
|
||||
}))
|
||||
|
||||
@ -105,6 +105,7 @@ func TestLoggerTemplate(t *testing.T) {
|
||||
req.Header.Add("User-Agent", "echo-tests-agent")
|
||||
req.Header.Add("X-Custom-Header", "AAA-CUSTOM-VALUE")
|
||||
req.Header.Add("X-Request-ID", "6ba7b810-9dad-11d1-80b4-00c04fd430c8")
|
||||
req.Header.Add("Cookie", "_ga=GA1.2.000000000.0000000000; session=ac08034cd216a647fc2eb62f2bcf7b810")
|
||||
req.Form = url.Values{
|
||||
"username": []string{"apagano-form"},
|
||||
"password": []string{"secret-form"},
|
||||
@ -129,6 +130,7 @@ func TestLoggerTemplate(t *testing.T) {
|
||||
"google.com": true,
|
||||
"echo-tests-agent": true,
|
||||
"6ba7b810-9dad-11d1-80b4-00c04fd430c8": true,
|
||||
"ac08034cd216a647fc2eb62f2bcf7b810": true,
|
||||
}
|
||||
|
||||
for token, present := range cases {
|
||||
|
Loading…
Reference in New Issue
Block a user