fix: correct logging if caller has generics (#7121)
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7121 Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
commit
ed85d1f2a9
|
@ -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
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package log
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func testGeneric[T any](log *LoggerImpl, t T) {
|
||||
log.Log(0, INFO, "Just testing the logging of a generic function %v", t)
|
||||
}
|
||||
|
||||
func TestLog(t *testing.T) {
|
||||
bufferWriter := NewEventWriterBuffer("test-buffer", WriterMode{
|
||||
Level: INFO,
|
||||
})
|
||||
|
||||
logger := NewLoggerWithWriters(t.Context(), "test", bufferWriter)
|
||||
|
||||
testGeneric(logger, "I'm the generic value!")
|
||||
logger.Close()
|
||||
|
||||
assert.Contains(t, bufferWriter.Buffer.String(), ".../logger_impl_test.go:13:testGeneric() [I] Just testing the logging of a generic function I'm the generic value!")
|
||||
}
|
Loading…
Reference in New Issue