In the following code pattern, the log message will get logged with v=0 in JSON
output although conceptually it has a higher verbosity:
if klog.V(5).Enabled() {
klog.Info("hello world")
}
Having the actual verbosity in the JSON output is relevant, for example for
filtering out only the important info messages. The solution is to use
klog.V(5).Info or something similar.
Whether the outer if is necessary at all depends on how complex the parameters
are. The return value of klog.V can be captured in a variable and be used
multiple times to avoid the overhead for that function call and to avoid
repeating the verbosity level.
Kubernetes-commit: 9eaa2dc554e0c3d4485d4c916dfdbc2f517db2e0
This commit is contained in:
Patrick Ohly2021-12-11 12:10:21 +01:00committed byKubernetes Publisher
// the queue’s start R is set to the virtual time.
// the queue’s start R is set to the virtual time.
queue.nextDispatchR=qs.currentR
queue.nextDispatchR=qs.currentR
ifklog.V(6).Enabled(){
klogV:=klog.V(6)
klog.Infof("QS(%s) at t=%s R=%v: initialized queue %d start R due to request %#+v %#+v",qs.qCfg.Name,now.Format(nsTimeFmt),queue.nextDispatchR,queue.index,request.descr1,request.descr2)
ifklogV.Enabled(){
klogV.Infof("QS(%s) at t=%s R=%v: initialized queue %d start R due to request %#+v %#+v",qs.qCfg.Name,now.Format(nsTimeFmt),queue.nextDispatchR,queue.index,request.descr1,request.descr2)
klog.Infof("QS(%s) at t=%s R=%v: immediate dispatch of request %q %#+v %#+v, qs will have %d executing",qs.qCfg.Name,now.Format(nsTimeFmt),qs.currentR,fsName,descr1,descr2,qs.totRequestsExecuting)
ifklogV.Enabled(){
klogV.Infof("QS(%s) at t=%s R=%v: immediate dispatch of request %q %#+v %#+v, qs will have %d executing",qs.qCfg.Name,now.Format(nsTimeFmt),qs.currentR,fsName,descr1,descr2,qs.totRequestsExecuting)
klog.Infof("QS(%s) at t=%s R=%v: dispatching request %#+v %#+v work %v from queue %d with start R %v, queue will have %d waiting & %d requests occupying %d seats, set will have %d seats occupied",
ifklogV.Enabled(){
klogV.Infof("QS(%s) at t=%s R=%v: dispatching request %#+v %#+v work %v from queue %d with start R %v, queue will have %d waiting & %d requests occupying %d seats, set will have %d seats occupied",
// since we have not picked the queue with the minimum virtual finish
// since we have not picked the queue with the minimum virtual finish
// time, we are not going to advance the round robin index here.
// time, we are not going to advance the round robin index here.
ifklog.V(4).Enabled(){
klogV:=klog.V(4)
klog.Infof("QS(%s): request %v %v seats %d cannot be dispatched from queue %d, waiting for currently executing requests to complete, %d requests are occupying %d seats and the limit is %d",
ifklogV.Enabled(){
klogV.Infof("QS(%s): request %v %v seats %d cannot be dispatched from queue %d, waiting for currently executing requests to complete, %d requests are occupying %d seats and the limit is %d",
// release the seats allocated to this request immediately
// release the seats allocated to this request immediately
releaseSeatsLocked()
releaseSeatsLocked()
if!klog.V(6).Enabled(){
if!klogV.Enabled(){
}elseifr.queue!=nil{
}elseifr.queue!=nil{
klog.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished all use of %d seats, adjusted queue %d start R to %v due to service time %.9fs, queue will have %d requests with %#v waiting & %d requests occupying %d seats",
klogV.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished all use of %d seats, adjusted queue %d start R to %v due to service time %.9fs, queue will have %d requests with %#v waiting & %d requests occupying %d seats",
klog.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished all use of %d seats, qs will have %d requests occupying %d seats",qs.qCfg.Name,now.Format(nsTimeFmt),qs.currentR,r.descr1,r.descr2,r.workEstimate.InitialSeats,qs.totRequestsExecuting,qs.totSeatsInUse)
klogV.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished all use of %d seats, qs will have %d requests occupying %d seats",qs.qCfg.Name,now.Format(nsTimeFmt),qs.currentR,r.descr1,r.descr2,r.workEstimate.InitialSeats,qs.totRequestsExecuting,qs.totSeatsInUse)
klog.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished main use of %d seats but lingering on %d seats for %v seconds, adjusted queue %d start R to %v due to service time %.9fs, queue will have %d requests with %#v waiting & %d requests occupying %d seats",
klogV.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished main use of %d seats but lingering on %d seats for %v seconds, adjusted queue %d start R to %v due to service time %.9fs, queue will have %d requests with %#v waiting & %d requests occupying %d seats",
klog.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished main use of %d seats but lingering on %d seats for %v seconds, qs will have %d requests occupying %d seats",qs.qCfg.Name,now.Format(nsTimeFmt),qs.currentR,r.descr1,r.descr2,r.workEstimate.InitialSeats,r.workEstimate.FinalSeats,additionalLatency.Seconds(),qs.totRequestsExecuting,qs.totSeatsInUse)
klogV.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished main use of %d seats but lingering on %d seats for %v seconds, qs will have %d requests occupying %d seats",qs.qCfg.Name,now.Format(nsTimeFmt),qs.currentR,r.descr1,r.descr2,r.workEstimate.InitialSeats,r.workEstimate.FinalSeats,additionalLatency.Seconds(),qs.totRequestsExecuting,qs.totSeatsInUse)
}
}
// EventAfterDuration will execute the event func in a new goroutine,
// EventAfterDuration will execute the event func in a new goroutine,
// so the seats allocated to this request will be released after
// so the seats allocated to this request will be released after
klog.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished lingering on %d seats, qs will have %d requests occupying %d seats",qs.qCfg.Name,now.Format(nsTimeFmt),qs.currentR,r.descr1,r.descr2,r.workEstimate.FinalSeats,qs.totRequestsExecuting,qs.totSeatsInUse)
klogV.Infof("QS(%s) at t=%s R=%v: request %#+v %#+v finished lingering on %d seats, qs will have %d requests occupying %d seats",qs.qCfg.Name,now.Format(nsTimeFmt),qs.currentR,r.descr1,r.descr2,r.workEstimate.FinalSeats,qs.totRequestsExecuting,qs.totSeatsInUse)