Codebase list golang-github-go-logr-logr / 12c72f2
funcr: don't copy each options field, copy options No functional change. Tim Hockin 2 years ago
1 changed file(s) with 17 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
167167
168168 func newFormatter(opts Options, outfmt outputFormat) Formatter {
169169 f := Formatter{
170 outputFormat: outfmt,
171 prefix: "",
172 values: nil,
173 depth: 0,
174 logCaller: opts.LogCaller,
175 logCallerFunc: opts.LogCallerFunc,
176 logTimestamp: opts.LogTimestamp,
177 verbosity: opts.Verbosity,
170 outputFormat: outfmt,
171 prefix: "",
172 values: nil,
173 depth: 0,
174 opts: opts,
178175 }
179176 return f
180177 }
183180 // implementation. It should be constructed with NewFormatter. Some of
184181 // its methods directly implement logr.LogSink.
185182 type Formatter struct {
186 outputFormat outputFormat
187 prefix string
188 values []interface{}
189 valuesStr string
190 depth int
191 logCaller MessageClass
192 logCallerFunc bool
193 logTimestamp bool
194 verbosity int
183 outputFormat outputFormat
184 prefix string
185 values []interface{}
186 valuesStr string
187 depth int
188 opts Options
195189 }
196190
197191 // outputFormat indicates which outputFormat to use.
489483 return callerID{"<unknown>", 0, ""}
490484 }
491485 fn := ""
492 if f.logCallerFunc {
486 if f.opts.LogCallerFunc {
493487 if fp := runtime.FuncForPC(pc); fp != nil {
494488 fn = fp.Name()
495489 }
507501
508502 // Enabled checks whether an info message at the given level should be logged.
509503 func (f Formatter) Enabled(level int) bool {
510 return level <= f.verbosity
504 return level <= f.opts.Verbosity
511505 }
512506
513507 // GetDepth returns the current depth of this Formatter. This is useful for
526520 args = append(args, "logger", prefix)
527521 prefix = ""
528522 }
529 if f.logTimestamp {
523 if f.opts.LogTimestamp {
530524 args = append(args, "ts", time.Now().Format(timestampFmt))
531525 }
532 if f.logCaller == All || f.logCaller == Info {
526 if policy := f.opts.LogCaller; policy == All || policy == Info {
533527 args = append(args, "caller", f.caller())
534528 }
535529 args = append(args, "level", level, "msg", msg)
546540 args = append(args, "logger", prefix)
547541 prefix = ""
548542 }
549 if f.logTimestamp {
543 if f.opts.LogTimestamp {
550544 args = append(args, "ts", time.Now().Format(timestampFmt))
551545 }
552 if f.logCaller == All || f.logCaller == Error {
546 if policy := f.opts.LogCaller; policy == All || policy == Error {
553547 args = append(args, "caller", f.caller())
554548 }
555549 args = append(args, "msg", msg)