You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-06-15 00:15:00 +02:00
Add exclude logging path option
Useful for excluding /ping endpoint to reduce log volume. This is somewhat more verbose than a simple bool to disable logging of the `/ping` endpoint. Perhaps better to add `-silence-ping-logging` bool flag to `options.go` and pass in the `/ping` endpoint as part of `logger` declaration in `options.go`. Could be extended into a slice of paths similar to go-gin's `SkipPaths`: https://github.com/gin-gonic/gin/blob/master/logger.go#L46
This commit is contained in:
@ -19,15 +19,15 @@ func TestLoggingHandler_ServeHTTP(t *testing.T) {
|
||||
Format,
|
||||
ExpectedLogMessage,
|
||||
Path string
|
||||
SilentPing bool
|
||||
ExcludePath string
|
||||
}{
|
||||
{logger.DefaultRequestLoggingFormat, fmt.Sprintf("127.0.0.1 - - [%s] test-server GET - \"/foo/bar\" HTTP/1.1 \"\" 200 4 0.000\n", logger.FormatTimestamp(ts)), "/foo/bar", false},
|
||||
{logger.DefaultRequestLoggingFormat, fmt.Sprintf("127.0.0.1 - - [%s] test-server GET - \"/foo/bar\" HTTP/1.1 \"\" 200 4 0.000\n", logger.FormatTimestamp(ts)), "/foo/bar", true},
|
||||
{logger.DefaultRequestLoggingFormat, fmt.Sprintf("127.0.0.1 - - [%s] test-server GET - \"/ping\" HTTP/1.1 \"\" 200 4 0.000\n", logger.FormatTimestamp(ts)), "/ping", false},
|
||||
{"{{.RequestMethod}}", "GET\n", "/foo/bar", false},
|
||||
{"{{.RequestMethod}}", "GET\n", "/foo/bar", true},
|
||||
{"{{.RequestMethod}}", "GET\n", "/ping", false},
|
||||
{"{{.RequestMethod}}", "", "/ping", true},
|
||||
{logger.DefaultRequestLoggingFormat, fmt.Sprintf("127.0.0.1 - - [%s] test-server GET - \"/foo/bar\" HTTP/1.1 \"\" 200 4 0.000\n", logger.FormatTimestamp(ts)), "/foo/bar", ""},
|
||||
{logger.DefaultRequestLoggingFormat, fmt.Sprintf("127.0.0.1 - - [%s] test-server GET - \"/foo/bar\" HTTP/1.1 \"\" 200 4 0.000\n", logger.FormatTimestamp(ts)), "/foo/bar", "/ping"},
|
||||
{logger.DefaultRequestLoggingFormat, fmt.Sprintf("127.0.0.1 - - [%s] test-server GET - \"/ping\" HTTP/1.1 \"\" 200 4 0.000\n", logger.FormatTimestamp(ts)), "/ping", ""},
|
||||
{"{{.RequestMethod}}", "GET\n", "/foo/bar", ""},
|
||||
{"{{.RequestMethod}}", "GET\n", "/foo/bar", "/ping"},
|
||||
{"{{.RequestMethod}}", "GET\n", "/ping", ""},
|
||||
{"{{.RequestMethod}}", "", "/ping", "/ping"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
@ -43,7 +43,7 @@ func TestLoggingHandler_ServeHTTP(t *testing.T) {
|
||||
|
||||
logger.SetOutput(buf)
|
||||
logger.SetReqTemplate(test.Format)
|
||||
logger.SetSilentPing(test.SilentPing)
|
||||
logger.SetExcludePath(test.ExcludePath)
|
||||
h := LoggingHandler(http.HandlerFunc(handler))
|
||||
|
||||
r, _ := http.NewRequest("GET", test.Path, nil)
|
||||
|
Reference in New Issue
Block a user