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

log: StdlibAdaptor timestamp value is weird in logfmt format #434

Closed
willfaught opened this issue Jan 11, 2017 · 6 comments
Closed

log: StdlibAdaptor timestamp value is weird in logfmt format #434

willfaught opened this issue Jan 11, 2017 · 6 comments

Comments

@willfaught
Copy link
Contributor

It's quoted and doesn't match the RFC3339 format of DefaultTimestamp/UTC:

timestamp=2017-01-11T12:58:52-08:00 caller=server.go:16 message=started
timestamp="2017/01/11 12:58:52.426762" caller=http.go:142 message="Serving [::]:8000 with pid 64404"
@peterbourgon
Copy link
Member

That's the way the stdlib timestamp comes to us. As far as I can tell, changing it would involve parsing and reformatting as time.RFC3339[Nano]. I'm not sure that juice is worth the squeeze. Do you think?

@ChrisHines
Copy link
Member

The quotes are required by logfmt because of the space in the value.

The date and time formatting done by the stdlib log package is hard coded and doesn't even use time.Format. We are already parsing in a fashion a regex. It may be possible to do a more thorough job and resolve this issue without loss of performance.

There is a workaround readily available, which is to turn off time recording on the stdlib log package and let the Go kit logger do that so that it is always consistent. See below.

package main

import (
	"log"
	"os"

	kitlog "github.com/go-kit/kit/log"
)

func main() {
	logger := kitlog.NewLogfmtLogger(os.Stdout)
	logger = kitlog.NewContext(logger).With("ts", kitlog.DefaultTimestampUTC)

	slog := kitlog.NewStdlibAdapter(logger)

	log.SetFlags(log.Lshortfile)
	log.SetOutput(slog)

	log.Println("hello world")
}

Output:

ts=2017-01-12T00:03:54Z file=a.go:19 msg="hello world"

@willfaught
Copy link
Contributor Author

@peterbourgon Ha, I've never heard that phrase before. :D

I was hoping it could be made uniform. It causes stutter in the terminal log output.

@ChrisHines Makes sense; forgot about the space.

Good idea about the workaround. I can use that.

@peterbourgon
Copy link
Member

We are already parsing in a fashion a regex. It may be possible to do a more thorough job and resolve this issue without loss of performance.

Good point. I'm open to this.

@peterbourgon
Copy link
Member

peterbourgon commented Jan 26, 2017

I reckon this is finished now that #438 is merged done.

@ChrisHines
Copy link
Member

Yes, it is finished. But to clarify, #438 was closed without merging.

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

3 participants