mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
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:
commit
83a8e42d03
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user