mirror of
https://codeberg.org/davrot/forgejo.git
synced 2025-05-19 02:00:01 +02:00
fix: correct logging if caller has generics
- If the caller function has generics then `runtime.FuncForPC(...).Name()` will not show the generic types and instead collapse it to `[...]`. Remove this suffix from the function name. - This fixes an issue where the logging of functions that use generics such as `db.Find` to be logged as `]()` instead of `Find()`, as the last dot in `[...]` was being used as a cutoff point. - Unit test added.
This commit is contained in:
parent
6b436955fc
commit
101efdd2e7
2 changed files with 28 additions and 1 deletions
|
@ -191,7 +191,7 @@ func (l *LoggerImpl) Log(skip int, level Level, format string, logArgs ...any) {
|
|||
if ok {
|
||||
fn := runtime.FuncForPC(pc)
|
||||
if fn != nil {
|
||||
event.Caller = fn.Name() + "()"
|
||||
event.Caller = strings.TrimSuffix(fn.Name(), "[...]") + "()"
|
||||
}
|
||||
}
|
||||
event.Filename, event.Line = strings.TrimPrefix(filename, projectPackagePrefix), line
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue