func (t *Trace) logTrace() {
	if t.durationIsWithinThreshold() {
		var buffer bytes.Buffer
		traceNum := rand.Int31()

		totalTime := t.endTime.Sub(t.startTime)
		buffer.WriteString(fmt.Sprintf("Trace[%d]: %q ", traceNum, t.name))
		if len(t.fields) > 0 {
			writeFields(&buffer, t.fields)
			buffer.WriteString(" ")
		}

		// if any step took more than it's share of the total allowed time, it deserves a higher log level
		buffer.WriteString(fmt.Sprintf("(%v) (total time: %vms):", t.startTime.Format("02-Jan-2006 15:04:00.000"), totalTime.Milliseconds()))
		stepThreshold := t.calculateStepThreshold()
		t.writeTraceSteps(&buffer, fmt.Sprintf("\nTrace[%d]: ", traceNum), stepThreshold)
		buffer.WriteString(fmt.Sprintf("\nTrace[%d]: [%v] [%v] END\n", traceNum, t.endTime.Sub(t.startTime), totalTime))

		klog.Info(buffer.String())
		return
	}

	// If the trace should not be logged, still check if nested traces should be logged
	for _, s := range t.traceItems {
		if nestedTrace, ok := s.(*Trace); ok {
			nestedTrace.logTrace()
		}
	}
}
// logTopLevelTraces finds all traces in a hierarchy of nested traces that should be logged but do not have any
// parents that will be logged, due to threshold limits, and logs them as top level traces.
logTopLevelTraces finds all traces in a hierarchy of nested traces that should be logged but do not have any
parents that will be logged, due to threshold limits, and logs them as top level traces.
// logTopLevelTraces finds all traces in a hierarchy of nested traces that should be logged but do not have any // parents that will be logged due to threshold limits and logs them as top level traces .
func (t *Trace) logTrace() {
	if t.durationIsWithinThreshold() {
		var buffer bytes.Buffer
		traceNum := rand.Int31()
		totalTime := t.endTime.Sub(t.startTime)
		buffer.WriteString(fmt.Sprintf("Trace[%d]: %q ", traceNum, t.name))
		if len(t.fields) > 0 {
			writeFields(&buffer, t.fields)
			buffer.WriteString(" ")
		}
		buffer.WriteString(fmt.Sprintf("(%v) (total time: %vms):", t.startTime.Format("02-Jan-2006 15:04:00.000"), totalTime.Milliseconds()))
		stepThreshold := t.calculateStepThreshold()
		t.writeTraceSteps(&buffer, fmt.Sprintf("\nTrace[%d]: ", traceNum), stepThreshold)
		buffer.WriteString(fmt.Sprintf("\nTrace[%d]: [%v] [%v] END\n", traceNum, t.endTime.Sub(t.startTime), totalTime))
		klog.Info(buffer.String())
		return
	}
	for _, s := range t.traceItems {
		if nestedTrace, ok := s.(*Trace); ok {
			nestedTrace.logTrace()
		}
	}
}
func ( t * Trace ) logTrace ( ) { if t . durationIsWithinThreshold ( ) { var buffer bytes . Buffer traceNum := rand . Int31 ( ) totalTime := t . endTime . Sub ( t . startTime ) buffer . WriteString ( fmt . Sprintf ( " " , traceNum , t . name ) ) if len ( t . fields ) > 0 { writeFields ( & buffer , t . fields ) buffer . WriteString ( " " ) } buffer . WriteString ( fmt . Sprintf ( " " , t . startTime . Format ( " " ) , totalTime . Milliseconds ( ) ) ) stepThreshold := t . calculateStepThreshold ( ) t . writeTraceSteps ( & buffer , fmt . Sprintf ( " \n " , traceNum ) , stepThreshold ) buffer . WriteString ( fmt . Sprintf ( " \n \n " , traceNum , t . endTime . Sub ( t . startTime ) , totalTime ) ) klog . Info ( buffer . String ( ) ) return } for _ , s := range t . traceItems { if nestedTrace , ok := s . ( * Trace ) ; ok { nestedTrace . logTrace ( ) } } }
logTopLevelTraces finds all traces in a hierarchy of nested traces that should be logged but do not have any
parents that will be logged, due to threshold limits, and logs them as top level traces.
logTopLevelTraces finds all traces in a hierarchy of nested traces that should be logged but do not have any parents that will be logged due to threshold limits and logs them as top level traces .
// if any step took more than it's share of the total allowed time, it deserves a higher log level // If the trace should not be logged, still check if nested traces should be logged