inconshreveable / log15

Structured, composable logging for Go
https://godoc.org/github.com/inconshreveable/log15
Other
1.1k stars 144 forks source link

invalid formatting directive #96

Closed kevinburke closed 8 years ago

kevinburke commented 8 years ago

go vet ./... warns:

handler.go:109: unrecognized printf verb 'n'

This is the line in question:

r.Ctx = append(r.Ctx, "fn", fmt.Sprintf("%+n", r.Call))

This commit has been around since 2014 at least. The fmt docs don't mention %n or %+n: https://golang.org/pkg/fmt/

I tried switching to %+s, %+v, %#v, but these all made the tests fail/changed the output, so I'm uncertain what rule Go is applying for that directive, or how to fix it.

ChrisHines commented 8 years ago

Look at the docs for github.com/go-stack/stack.

On Sat, Jul 9, 2016, 6:14 PM Kevin Burke notifications@github.com wrote:

go vet ./... warns:

handler.go:109: unrecognized printf verb 'n'

This is the line in question:

r.Ctx = append(r.Ctx, "fn", fmt.Sprintf("%+n", r.Call))

This commit has been around since 2014 at least. The fmt docs don't mention %n or %+n: https://golang.org/pkg/fmt/

I tried switching to %+s, %+v, %#v, but these all made the tests fail/changed the output, so I'm uncertain what rule Go is applying for that directive, or how to fix it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/inconshreveable/log15/issues/96, or mute the thread https://github.com/notifications/unsubscribe/ABAvZ5m2w1DeqqfuEckIdfJy0d1lX49Dks5qUB0_gaJpZM4JItqk .

ChrisHines commented 8 years ago

Also, go vet isn't perfect.

On Sat, Jul 9, 2016, 6:15 PM Chris Hines chris@cs-guy.com wrote:

Look at the docs for github.com/go-stack/stack.

On Sat, Jul 9, 2016, 6:14 PM Kevin Burke notifications@github.com wrote:

go vet ./... warns:

handler.go:109: unrecognized printf verb 'n'

This is the line in question:

r.Ctx = append(r.Ctx, "fn", fmt.Sprintf("%+n", r.Call))

This commit has been around since 2014 at least. The fmt docs don't mention %n or %+n: https://golang.org/pkg/fmt/

I tried switching to %+s, %+v, %#v, but these all made the tests fail/changed the output, so I'm uncertain what rule Go is applying for that directive, or how to fix it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/inconshreveable/log15/issues/96, or mute the thread https://github.com/notifications/unsubscribe/ABAvZ5m2w1DeqqfuEckIdfJy0d1lX49Dks5qUB0_gaJpZM4JItqk .

kevinburke commented 8 years ago

Yeah, it's the only thing warning in my application though. FWIW I tried calling r.Call.Format() directly but it's not easy to construct a fmt.State manually. :(

inconshreveable commented 8 years ago

Yep, not a bug. Basically, you can define the Formatter interface and define your own custom formatting directives like %+#z. go-stack does exactly that and go vet like Chris said is not intelligent enough to understand that's possible. i'm not sure if go vet accepts comments to suppress warnings, but that might be a decent solution to this problem