@@ -58,6 +58,7 @@ type configOptions struct {
58
58
vmoduleFlagName string
59
59
verbosityDefault int
60
60
fixedTime * time.Time
61
+ unwind func (int ) (string , int )
61
62
output io.Writer
62
63
}
63
64
@@ -105,6 +106,21 @@ func FixedTime(ts time.Time) ConfigOption {
105
106
}
106
107
}
107
108
109
+ // Backtrace overrides the default mechanism for determining the call site.
110
+ // The callback is invoked with the number of function calls between itself
111
+ // and the call site. It must return the file name and line number. An empty
112
+ // file name indicates that the information is unknown.
113
+ //
114
+ // # Experimental
115
+ //
116
+ // Notice: This function is EXPERIMENTAL and may be changed or removed in a
117
+ // later release.
118
+ func Backtrace (unwind func (skip int ) (filename string , line int )) ConfigOption {
119
+ return func (co * configOptions ) {
120
+ co .unwind = unwind
121
+ }
122
+ }
123
+
108
124
// NewConfig returns a configuration with recommended defaults and optional
109
125
// modifications. Command line flags are not bound to any FlagSet yet.
110
126
func NewConfig (opts ... ConfigOption ) * Config {
@@ -114,6 +130,7 @@ func NewConfig(opts ...ConfigOption) *Config {
114
130
verbosityFlagName : "v" ,
115
131
vmoduleFlagName : "vmodule" ,
116
132
verbosityDefault : 0 ,
133
+ unwind : runtimeBacktrace ,
117
134
output : os .Stderr ,
118
135
},
119
136
}
@@ -127,6 +144,10 @@ func NewConfig(opts ...ConfigOption) *Config {
127
144
}
128
145
129
146
// AddFlags registers the command line flags that control the configuration.
147
+ //
148
+ // The default flag names are the same as in klog, so unless those defaults
149
+ // are changed, either klog.InitFlags or Config.AddFlags can be used for the
150
+ // same flag set, but not both.
130
151
func (c * Config ) AddFlags (fs * flag.FlagSet ) {
131
152
fs .Var (c .Verbosity (), c .co .verbosityFlagName , "number for the log level verbosity of the testing logger" )
132
153
fs .Var (c .VModule (), c .co .vmoduleFlagName , "comma-separated list of pattern=N log level settings for files matching the patterns" )
0 commit comments