-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add URL and Host for some access logs.
- Loading branch information
Showing
3 changed files
with
79 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package accesslog | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/urfave/negroni" | ||
) | ||
|
||
// SaveFrontend sends the frontend name to the logger. | ||
// These are sometimes used with a corresponding SaveBackend handler, but not always. | ||
// For example, redirected requests don't reach a backend. | ||
type SaveFrontend struct { | ||
next http.Handler | ||
frontendName string | ||
} | ||
|
||
// NewSaveFrontend creates a SaveFrontend handler. | ||
func NewSaveFrontend(next http.Handler, frontendName string) http.Handler { | ||
return &SaveFrontend{next, frontendName} | ||
} | ||
|
||
func (sf *SaveFrontend) ServeHTTP(rw http.ResponseWriter, r *http.Request) { | ||
serveSaveFrontend(r, sf.frontendName, func() { | ||
sf.next.ServeHTTP(rw, r) | ||
}) | ||
} | ||
|
||
// SaveNegroniFrontend sends the frontend name to the logger. | ||
type SaveNegroniFrontend struct { | ||
next negroni.Handler | ||
frontendName string | ||
} | ||
|
||
// NewSaveNegroniFrontend creates a SaveNegroniFrontend handler. | ||
func NewSaveNegroniFrontend(next negroni.Handler, frontendName string) negroni.Handler { | ||
return &SaveNegroniFrontend{next, frontendName} | ||
} | ||
|
||
func (sf *SaveNegroniFrontend) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { | ||
serveSaveFrontend(r, sf.frontendName, func() { | ||
sf.next.ServeHTTP(rw, r, next) | ||
}) | ||
} | ||
|
||
func serveSaveFrontend(r *http.Request, frontendName string, apply func()) { | ||
table := GetLogDataTable(r) | ||
table.Core[FrontendName] = strings.TrimPrefix(frontendName, "frontend-") | ||
|
||
apply() | ||
} |