var klogV … type Field … func (f Field) format() string { … } func writeFields(b *bytes.Buffer, l []Field) { … } func writeTraceItemSummary(b *bytes.Buffer, msg string, totalTime time.Duration, startTime time.Time, fields []Field) { … } func durationToMilliseconds(timeDuration time.Duration) int64 { … } type traceItem … type traceStep … // rLock doesn't need to do anything because traceStep instances are immutable. func (s traceStep) rLock() { … } func (s traceStep) rUnlock() { … } func (s traceStep) time() time.Time { … } func (s traceStep) writeItem(b *bytes.Buffer, formatter string, startTime time.Time, stepThreshold *time.Duration) { … } type Trace … func (t *Trace) rLock() { … } func (t *Trace) rUnlock() { … } func (t *Trace) time() time.Time { … } func (t *Trace) writeItem(b *bytes.Buffer, formatter string, startTime time.Time, stepThreshold *time.Duration) { … } // New creates a Trace with the specified name. The name identifies the operation to be traced. The // Fields add key value pairs to provide additional details about the trace, such as operation inputs. func New(name string, fields ...Field) *Trace { … } // Step adds a new step with a specific message. Call this at the end of an execution step to record // how long it took. The Fields add key value pairs to provide additional details about the trace // step. func (t *Trace) Step(msg string, fields ...Field) { … } // Nest adds a nested trace with the given message and fields and returns it. // As a convenience, if the receiver is nil, returns a top level trace. This allows // one to call FromContext(ctx).Nest without having to check if the trace // in the context is nil. func (t *Trace) Nest(msg string, fields ...Field) *Trace { … } // Log is used to dump all the steps in the Trace. It also logs the nested trace messages using indentation. // If the Trace is nested it is not immediately logged. Instead, it is logged when the trace it is nested within // is logged. func (t *Trace) Log() { … } // LogIfLong only logs the trace if the duration of the trace exceeds the threshold. // Only steps that took longer than their share or the given threshold are logged. // If klog is at verbosity level 4 or higher and the trace took longer than the threshold, // all substeps and subtraces are logged. Otherwise, only those which took longer than // their own threshold. // If the Trace is nested it is not immediately logged. Instead, it is logged when the trace it // is nested within is logged. func (t *Trace) LogIfLong(threshold time.Duration) { … } // 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() { … } func (t *Trace) writeTraceSteps(b *bytes.Buffer, formatter string, stepThreshold *time.Duration) { … } func (t *Trace) durationIsWithinThreshold() bool { … } // TotalTime can be used to figure out how long it took since the Trace was created func (t *Trace) TotalTime() time.Duration { … } // calculateStepThreshold returns a threshold for the individual steps of a trace, or nil if there is no threshold and // all steps should be written. func (t *Trace) calculateStepThreshold() *time.Duration { … } type ContextTraceKey … // FromContext returns the trace keyed by ContextTraceKey in the context values, if one // is present, or nil If there is no trace in the Context. // It is safe to call Nest() on the returned value even if it is nil because ((*Trace)nil).Nest returns a top level // trace. func FromContext(ctx context.Context) *Trace { … } // ContextWithTrace returns a context with trace included in the context values, keyed by ContextTraceKey. func ContextWithTrace(ctx context.Context, trace *Trace) context.Context { … }