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 flag to display ISO 8601 date and time format #34416

Closed
IPv4v6 opened this issue Sep 19, 2019 · 7 comments
Closed

proposal: log: add flag to display ISO 8601 date and time format #34416

IPv4v6 opened this issue Sep 19, 2019 · 7 comments

Comments

@IPv4v6
Copy link

@IPv4v6 IPv4v6 commented Sep 19, 2019

go version go1.12.9 linux/amd64

package main

import "log"

func main() {
	log.Println("foobar")
}

Output: 2019/09/19 22:49:58 foobar

There is no option to specify the output format with the timezone included.

@smasher164

This comment has been minimized.

Copy link
Member

@smasher164 smasher164 commented Sep 19, 2019

The LUTC flag will log the date/time in UTC. This should be enough to then convert to a local timezone. Does this satisfy your requirement?

@IPv4v6

This comment has been minimized.

Copy link
Author

@IPv4v6 IPv4v6 commented Oct 17, 2019

I think it would be better to add a new flag to output the ISO 8601 format directly. Like in the Unix 'date' command:

$ date --iso-8601=seconds
2019-10-17T22:13:31+02:00

No need to convert between timezones, just print the time with timezone information.

@smasher164 smasher164 changed the title log: implement ISO 8601 date and time format with timezone proposal: log: add flag to display ISO 8601 date and time format Nov 12, 2019
@gopherbot gopherbot added this to the Proposal milestone Nov 12, 2019
@smasher164

This comment has been minimized.

Copy link
Member

@smasher164 smasher164 commented Nov 12, 2019

Marking this as proposal so it goes through the appropriate channels.
/cc @robpike

@smasher164 smasher164 added the Proposal label Nov 12, 2019
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Nov 21, 2019

We can add an infinite number of flags to package log to format the time.
If you need a specific formatting of the time, it seems like it makes more sense to call log.SetOutput with a custom io.Writer that inserts the time itself.

@smasher164

This comment has been minimized.

Copy link
Member

@smasher164 smasher164 commented Nov 24, 2019

Something like this could suffice: https://play.golang.org/p/Ky4tu3FSHhV

@rsc rsc added this to Incoming in Proposals Nov 27, 2019
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Nov 27, 2019

Thanks @smasher164.
It seems like this is a likely decline - it's not common enough to be worth adding to the core API and it can be easily implemented outside.

Leaving open for a week for final comments.

@rsc rsc moved this from Incoming to Likely Decline in Proposals Dec 4, 2019
@rsc

This comment has been minimized.

Copy link
Contributor

@rsc rsc commented Dec 4, 2019

No change in consensus, so declining.

@rsc rsc closed this Dec 4, 2019
@rsc rsc moved this from Likely Decline to Declined in Proposals Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Proposals
Declined
5 participants
You can’t perform that action at this time.