Merge pull request #65678 from hzxuzhonghu/patch-4

Automatic merge from submit-queue (batch tested with PRs 65593, 65678). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

simplify httplog.LogOf

**What this PR does / why we need it**:

LogOf returns the logger hiding in w, otherwise returns a passthroughLogger, and it never panics.

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2018-07-02 02:22:00 -07:00 committed by GitHub
commit 83a8e42d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -100,14 +100,11 @@ func NewLogged(req *http.Request, w *http.ResponseWriter) *respLogger {
// then a passthroughLogger will be created which will log to stdout immediately // then a passthroughLogger will be created which will log to stdout immediately
// when Addf is called. // when Addf is called.
func LogOf(req *http.Request, w http.ResponseWriter) logger { func LogOf(req *http.Request, w http.ResponseWriter) logger {
if _, exists := w.(*respLogger); !exists {
pl := &passthroughLogger{}
return pl
}
if rl, ok := w.(*respLogger); ok { if rl, ok := w.(*respLogger); ok {
return rl return rl
} }
panic("Unable to find or create the logger!")
return &passthroughLogger{}
} }
// Unlogged returns the original ResponseWriter, or w if it is not our inserted logger. // Unlogged returns the original ResponseWriter, or w if it is not our inserted logger.