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

proposal: log: add Lshortpkg, Llongpkg flag #21761

Closed
azihsoyn opened this issue Sep 5, 2017 · 3 comments
Closed

proposal: log: add Lshortpkg, Llongpkg flag #21761

azihsoyn opened this issue Sep 5, 2017 · 3 comments

Comments

@azihsoyn
Copy link

azihsoyn commented Sep 5, 2017

log package already has Lshortfile and Llongfile flags for output file name.
But file name is not unique in huge product, and Llongfile flag may too long output.

My Proposal may solve above situation. like this

package directory

internal/foo/bar/baz.go

baz.go

package bazpkg // outputs bazpkg not baz

func doSomething(){
	log.Println("error")
	// outputs: if Lshortpkg set
	// bazpkg: error
	//
	// outputs: if Llongpkg set
	// internal/foo/bar/bazpkg: error
}

I am thinking this may hard to realize this because obtain pkg name is not easy current (reflect or runtime).

Thanks.

@gopherbot gopherbot added this to the Proposal milestone Sep 5, 2017
@mattn
Copy link
Member

mattn commented Sep 5, 2017

The package name must be decided the path on compile time but Go's binary doesn't have long package name. runtime package provide runtime.FuncForPC(pc).Name() but it's short name. It may be possible to pick-up package name from file name by runtime.Caller but it won't work for running go run command.

@azihsoyn
Copy link
Author

azihsoyn commented Sep 6, 2017

I understand go's package have name and path. (https://blog.golang.org/package-names)

And I found go/build package to obtain package name using go/ast. (https://golang.org/pkg/go/build/#Import)

But using it to log package is may too expensive.

@rsc
Copy link
Contributor

rsc commented Oct 16, 2017

It might be possible to back the package out of the runtime.Func's Name() method result, but in general we don't know the package. It's also unclear why the filename, which is only just a little longer than the package path, is too long but the package path is not. It really seems like in a huge project you'd want all the info you can get, namely the full file path.

The log flag seem to be working well for most people. We should probably avoid the complexity of new ones unless there is a repeated, compelling need.

@rsc rsc closed this as completed Oct 16, 2017
@golang golang locked and limited conversation to collaborators Oct 16, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants