Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否在日志信息中以相对路径的方式输出所在文件路径? #102

Closed
VeblenXSYK opened this issue May 14, 2019 · 3 comments
Closed

Comments

@VeblenXSYK
Copy link

显示日志信息所在文件为绝对路径,如下所示:

[2019/05/12 22:22:21.459] [C:/xxx/service/src/storeserv/internal/service/service.go:51] storeserv start
[2019/05/12 22:22:21.469] [C:/xxx/service/src/github.com/bilibili/kratos/pkg/net/http/blademaster/server.go:97] blademaster: start http listen addr: 0.0.0.0:6060

能否改为以GOPATH为准的相对路径?这样既能清晰显示日志信息,又能节省不必要的日志内容。

@tomwei7
Copy link
Contributor

tomwei7 commented May 14, 2019

Golang 无法再编译时获取 GOPATH 参数,来去除 GOPATH 前缀。不过可以通过传递编译参数 all=-trimpath= 来去除部分文件路径

go build -o {target_path} -gcflags "all=-trimpath=${GOPATH}/src" {source_file}

这样就相当于显示已 ${GOPATH}/src 为准的相对路径

@tomwei7 tomwei7 closed this as completed May 14, 2019
@reatang
Copy link

reatang commented Nov 6, 2024

补充:

go build -o main -gcflags "all=-trimpath=${GOPATH}/pkg/mod;${PWD}" main.go

支持去除多个路径的前缀

@kratos-ci-bot
Copy link
Collaborator

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Replenish:

go build -o main -gcflags "all=-trimpath=${GOPATH}/pkg/mod;${PWD}" main.go

Supports removing prefixes from multiple paths

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants