diff options
author | 2024-09-20 13:30:33 +0000 | |
---|---|---|
committer | 2024-09-20 13:30:33 +0000 | |
commit | 77b095a8c32c423dea495f94babe49d7f169f060 (patch) | |
tree | 47d23864fb256823919e2ddeb2ebc75c85421166 /internal/log/caller.go | |
parent | [chore/frontend] Make ecks pee theme even more ecks pee er (#3324) (diff) | |
download | gotosocial-77b095a8c32c423dea495f94babe49d7f169f060.tar.xz |
[chore] ensure consistent caller name fetching regardless of compiler inlining (#3323)
* move logging levels into log package itself
* ensure inconsistent inlining doesn't mess with log calling function name
* remove unused global variable
* fix log level
Diffstat (limited to 'internal/log/caller.go')
-rw-r--r-- | internal/log/caller.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/internal/log/caller.go b/internal/log/caller.go index 75b8d82d9..5385b63b5 100644 --- a/internal/log/caller.go +++ b/internal/log/caller.go @@ -23,11 +23,13 @@ import ( ) // Caller fetches the calling function name, skipping 'depth'. +// +//go:noinline func Caller(depth int) string { - var pcs [1]uintptr + pcs := make([]uintptr, 1) - // Fetch calling function using calldepth - _ = runtime.Callers(depth, pcs[:]) + // Fetch calling func using depth. + _ = runtime.Callers(depth, pcs) fn := runtime.FuncForPC(pcs[0]) if fn == nil { @@ -37,14 +39,14 @@ func Caller(depth int) string { // Get func name. name := fn.Name() - // Drop all but the package name and function name, no mod path + // Drop all but package and function name, no path. if idx := strings.LastIndex(name, "/"); idx >= 0 { name = name[idx+1:] } const params = `[...]` - // Drop any generic type parameter markers + // Drop any function generic type parameter markers. if idx := strings.Index(name, params); idx >= 0 { name = name[:idx] + name[idx+len(params):] } |