Skip to content

Commit be77ede

Browse files
zeripathwxiaoguang
andauthored
Change some logging levels (#18421)
* Change some logging levels * PlainTextWithBytes - 4xx/5xx this should just be TRACE * notFoundInternal - the "error" here is too noisy and should be DEBUG * WorkerPool - Worker pool scaling messages are normal and should be DEBUG Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: wxiaoguang <[email protected]>
1 parent e19b965 commit be77ede

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

modules/context/context.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (ctx *Context) NotFound(logMsg string, logErr error) {
232232

233233
func (ctx *Context) notFoundInternal(logMsg string, logErr error) {
234234
if logErr != nil {
235-
log.ErrorWithSkip(2, "%s: %v", logMsg, logErr)
235+
log.Log(2, log.DEBUG, "%s: %v", logMsg, logErr)
236236
if !setting.IsProd {
237237
ctx.Data["ErrorMsg"] = logErr
238238
}
@@ -248,7 +248,7 @@ func (ctx *Context) notFoundInternal(logMsg string, logErr error) {
248248
}
249249

250250
if !showHTML {
251-
ctx.PlainText(http.StatusNotFound, "Not found.\n")
251+
ctx.plainTextInternal(3, http.StatusNotFound, []byte("Not found.\n"))
252252
return
253253
}
254254

@@ -286,21 +286,27 @@ func (ctx *Context) NotFoundOrServerError(logMsg string, errCheck func(error) bo
286286
}
287287

288288
// PlainTextBytes renders bytes as plain text
289-
func (ctx *Context) PlainTextBytes(status int, bs []byte) {
290-
if (status/100 == 4) || (status/100 == 5) {
291-
log.Error("PlainTextBytes: %s", string(bs))
289+
func (ctx *Context) plainTextInternal(skip, status int, bs []byte) {
290+
statusPrefix := status / 100
291+
if statusPrefix == 4 || statusPrefix == 5 {
292+
log.Log(skip, log.TRACE, "plainTextInternal (status=%d): %s", status, string(bs))
292293
}
293294
ctx.Resp.WriteHeader(status)
294295
ctx.Resp.Header().Set("Content-Type", "text/plain;charset=utf-8")
295296
ctx.Resp.Header().Set("X-Content-Type-Options", "nosniff")
296297
if _, err := ctx.Resp.Write(bs); err != nil {
297-
log.Error("Write bytes failed: %v", err)
298+
log.ErrorWithSkip(skip, "plainTextInternal (status=%d): write bytes failed: %v", status, err)
298299
}
299300
}
300301

302+
// PlainTextBytes renders bytes as plain text
303+
func (ctx *Context) PlainTextBytes(status int, bs []byte) {
304+
ctx.plainTextInternal(2, status, bs)
305+
}
306+
301307
// PlainText renders content as plain text
302308
func (ctx *Context) PlainText(status int, text string) {
303-
ctx.PlainTextBytes(status, []byte(text))
309+
ctx.plainTextInternal(2, status, []byte(text))
304310
}
305311

306312
// RespHeader returns the response header

modules/queue/workerpool.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ func (p *WorkerPool) zeroBoost() {
118118
boost = p.maxNumberOfWorkers - p.numberOfWorkers
119119
}
120120
if mq != nil {
121-
log.Warn("WorkerPool: %d (for %s) has zero workers - adding %d temporary workers for %s", p.qid, mq.Name, boost, p.boostTimeout)
121+
log.Debug("WorkerPool: %d (for %s) has zero workers - adding %d temporary workers for %s", p.qid, mq.Name, boost, p.boostTimeout)
122122

123123
start := time.Now()
124124
pid := mq.RegisterWorkers(boost, start, true, start.Add(p.boostTimeout), cancel, false)
125125
cancel = func() {
126126
mq.RemoveWorkers(pid)
127127
}
128128
} else {
129-
log.Warn("WorkerPool: %d has zero workers - adding %d temporary workers for %s", p.qid, p.boostWorkers, p.boostTimeout)
129+
log.Debug("WorkerPool: %d has zero workers - adding %d temporary workers for %s", p.qid, p.boostWorkers, p.boostTimeout)
130130
}
131131
p.lock.Unlock()
132132
p.addWorkers(ctx, cancel, boost)
@@ -163,7 +163,7 @@ func (p *WorkerPool) pushBoost(data Data) {
163163
boost = p.maxNumberOfWorkers - p.numberOfWorkers
164164
}
165165
if mq != nil {
166-
log.Warn("WorkerPool: %d (for %s) Channel blocked for %v - adding %d temporary workers for %s, block timeout now %v", p.qid, mq.Name, ourTimeout, boost, p.boostTimeout, p.blockTimeout)
166+
log.Debug("WorkerPool: %d (for %s) Channel blocked for %v - adding %d temporary workers for %s, block timeout now %v", p.qid, mq.Name, ourTimeout, boost, p.boostTimeout, p.blockTimeout)
167167

168168
start := time.Now()
169169
pid := mq.RegisterWorkers(boost, start, true, start.Add(p.boostTimeout), boostCtxCancel, false)
@@ -173,7 +173,7 @@ func (p *WorkerPool) pushBoost(data Data) {
173173
boostCtxCancel()
174174
}()
175175
} else {
176-
log.Warn("WorkerPool: %d Channel blocked for %v - adding %d temporary workers for %s, block timeout now %v", p.qid, ourTimeout, p.boostWorkers, p.boostTimeout, p.blockTimeout)
176+
log.Debug("WorkerPool: %d Channel blocked for %v - adding %d temporary workers for %s, block timeout now %v", p.qid, ourTimeout, p.boostWorkers, p.boostTimeout, p.blockTimeout)
177177
}
178178
go func() {
179179
<-time.After(p.boostTimeout)

0 commit comments

Comments
 (0)