You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the logger in a Go module with a major version suffix, the package name is omitted, leaving only the version. In this case [email protected]. I would expect this to be go-pkg/[email protected]. go.mod:
module github.com/me/go-pkg/v2
go 1.19
require go.uber.org/zap v1.24.0
package main
import"github.com/me/go-pkg/v2"funcmain() {
pkg.LogSomething()
}
Results in the following log:
{"level":"info","ts":1669917064.3370209,"caller":"[email protected]/pkg.go:9","msg":"logging from library"}
The text was updated successfully, but these errors were encountered:
deitrix
changed the title
Incorrect caller when used in a package with a major version greater than v1
Incorrect caller when used in a Go module with a version suffix
Dec 1, 2022
deitrix
changed the title
Incorrect caller when used in a Go module with a version suffix
Incorrect caller when logs originate from modules with a major version suffix
Dec 1, 2022
This is caused by the logic in TrimmedPath which drops all but the final directory name. v2 is just another path of the package.
To solve this, we'd need a bit of a hack -- if we see v<N>@v<N>. at the beginning of the last directory path, we assume it's a version and use the previous / to get the directory instead.
When using the logger in a Go module with a major version suffix, the package name is omitted, leaving only the version. In this case
[email protected]
. I would expect this to bego-pkg/[email protected]
.go.mod
:log.go
:Using the above library in another Go project:
Results in the following log:
The text was updated successfully, but these errors were encountered: