@@ -67,7 +67,6 @@ type respLogger struct {
6767 addedInfo strings.Builder
6868 addedKeyValuePairs []interface {}
6969 startTime time.Time
70- isTerminating bool
7170
7271 captureErrorOutput bool
7372
@@ -101,13 +100,13 @@ func DefaultStacktracePred(status int) bool {
101100const withLoggingLevel = 3
102101
103102// WithLogging wraps the handler with logging.
104- func WithLogging (handler http.Handler , pred StacktracePred , isTerminatingFn func () bool ) http.Handler {
103+ func WithLogging (handler http.Handler , pred StacktracePred ) http.Handler {
105104 return withLogging (handler , pred , func () bool {
106105 return klog .V (withLoggingLevel ).Enabled ()
107- }, isTerminatingFn )
106+ })
108107}
109108
110- func withLogging (handler http.Handler , stackTracePred StacktracePred , shouldLogRequest ShouldLogRequestPred , isTerminatingFn func () bool ) http.Handler {
109+ func withLogging (handler http.Handler , stackTracePred StacktracePred , shouldLogRequest ShouldLogRequestPred ) http.Handler {
111110 return http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
112111 if ! shouldLogRequest () {
113112 handler .ServeHTTP (w , req )
@@ -118,16 +117,14 @@ func withLogging(handler http.Handler, stackTracePred StacktracePred, shouldLogR
118117 if old := respLoggerFromRequest (req ); old != nil {
119118 panic ("multiple WithLogging calls!" )
120119 }
120+
121121 startTime := time .Now ()
122122 if receivedTimestamp , ok := request .ReceivedTimestampFrom (ctx ); ok {
123123 startTime = receivedTimestamp
124124 }
125125
126- isTerminating := false
127- if isTerminatingFn != nil {
128- isTerminating = isTerminatingFn ()
129- }
130- rl := newLoggedWithStartTime (req , w , startTime ).StacktraceWhen (stackTracePred ).IsTerminating (isTerminating )
126+ rl := newLoggedWithStartTime (req , w , startTime )
127+ rl .StacktraceWhen (stackTracePred )
131128 req = req .WithContext (context .WithValue (ctx , respLoggerContextKey , rl ))
132129
133130 var logFunc func ()
@@ -138,9 +135,6 @@ func withLogging(handler http.Handler, stackTracePred StacktracePred, shouldLogR
138135 }
139136 }()
140137
141- if klog .V (3 ).Enabled () || (rl .isTerminating && klog .V (1 ).Enabled ()) {
142- defer rl .Log ()
143- }
144138 w = responsewriter .WrapForHTTP1Or2 (rl )
145139 handler .ServeHTTP (w , req )
146140
@@ -211,12 +205,6 @@ func (rl *respLogger) StacktraceWhen(pred StacktracePred) *respLogger {
211205 return rl
212206}
213207
214- // IsTerminating informs the logger that the server is terminating.
215- func (rl * respLogger ) IsTerminating (is bool ) * respLogger {
216- rl .isTerminating = is
217- return rl
218- }
219-
220208// StatusIsNot returns a StacktracePred which will cause stacktraces to be logged
221209// for any status *not* in the given list.
222210func StatusIsNot (statuses ... int ) StacktracePred {
0 commit comments