Fix error log when loading issues caused by a xorm bug (#7271)

* fix error log when loading issues caused by a xorm bug

* upgrade packages

* fix fmt

* fix Consistency

* fix tests
This commit is contained in:
Lunny Xiao 2019-06-23 23:22:43 +08:00 committed by Lauris BH
parent baefea311f
commit aa7c34cf86
156 changed files with 1854 additions and 1833 deletions

View file

@ -3,7 +3,6 @@
// license that can be found in the LICENSE file.
// +build !appengine
// +build go1.7
package internal
@ -130,7 +129,13 @@ func handleHTTP(w http.ResponseWriter, r *http.Request) {
flushes++
}
c.pendingLogs.Unlock()
go c.flushLog(false)
flushed := make(chan struct{})
go func() {
defer close(flushed)
// Force a log flush, because with very short requests we
// may not ever flush logs.
c.flushLog(true)
}()
w.Header().Set(logFlushHeader, strconv.Itoa(flushes))
// Avoid nil Write call if c.Write is never called.
@ -140,6 +145,9 @@ func handleHTTP(w http.ResponseWriter, r *http.Request) {
if c.outBody != nil {
w.Write(c.outBody)
}
// Wait for the last flush to complete before returning,
// otherwise the security ticket will not be valid.
<-flushed
}
func executeRequestSafely(c *context, r *http.Request) {
@ -571,7 +579,10 @@ func logf(c *context, level int64, format string, args ...interface{}) {
Level: &level,
Message: &s,
})
log.Print(logLevelName[level] + ": " + s)
// Only duplicate log to stderr if not running on App Engine second generation
if !IsSecondGen() {
log.Print(logLevelName[level] + ": " + s)
}
}
// flushLog attempts to flush any pending logs to the appserver.