MCPcopy
hub / github.com/op/go-logging / formatFuncName

Function formatFuncName

format.go:341–360  ·  view source on GitHub ↗

formatFuncName tries to extract certain part of the runtime formatted function name to some pre-defined variation. This function is known to not work properly if the package path or name contains a dot.

(v fmtVerb, f string)

Source from the content-addressed store, hash-verified

339// This function is known to not work properly if the package path or name
340// contains a dot.
341func formatFuncName(v fmtVerb, f string) string {
342 i := strings.LastIndex(f, "/")
343 j := strings.Index(f[i+1:], ".")
344 if j < 1 {
345 return "???"
346 }
347 pkg, fun := f[:i+j+1], f[i+j+2:]
348 switch v {
349 case fmtVerbLongpkg:
350 return pkg
351 case fmtVerbShortpkg:
352 return path.Base(pkg)
353 case fmtVerbLongfunc:
354 return fun
355 case fmtVerbShortfunc:
356 i = strings.LastIndex(fun, ".")
357 return fun[i+1:]
358 }
359 panic("unexpected func formatter")
360}
361
362func formatCallpath(calldepth int, depth int) string {
363 v := ""

Callers 3

TestFormatFuncNameFunction · 0.85
FormatMethod · 0.85
formatCallpathFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestFormatFuncNameFunction · 0.68