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
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.
The text was updated successfully, but these errors were encountered:
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.
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.
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
baz.go
I am thinking this may hard to realize this because obtain pkg name is not easy current (reflect or runtime).
Thanks.
The text was updated successfully, but these errors were encountered: