Skip to content

Commit

Permalink
Merge pull request kubernetes#65678 from hzxuzhonghu/patch-4
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
Kubernetes Submit Queue authored Jul 2, 2018
2 parents 7496c64 + 1c5a021 commit 83a8e42
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions staging/src/k8s.io/apiserver/pkg/server/httplog/httplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// when Addf is called.
func LogOf(req *http.Request, w http.ResponseWriter) logger {
if _, exists := w.(*respLogger); !exists {
pl := &passthroughLogger{}
return pl
}
if rl, ok := w.(*respLogger); ok {
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.
Expand Down

0 comments on commit 83a8e42

Please sign in to comment.