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 use hyphen instead of slash as separator #50203

Open
TwiN opened this issue Dec 16, 2021 · 1 comment
Open

proposal: log: add flag to use hyphen instead of slash as separator #50203

TwiN opened this issue Dec 16, 2021 · 1 comment
Labels
Projects
Milestone

Comments

@TwiN
Copy link

@TwiN TwiN commented Dec 16, 2021

What version of Go are you using (go version)?

$ go version
1.17.1

Does this issue reproduce with the latest release?

Yes

What did you do?

package main

import "log"

func main() {
    log.Println("Hello, world.")
}

What did you expect to see?

2021-12-15 19:12:34 Hello, world.

To clarify, I'd be fine with this being configurable via a flag (i.e. log.SetFlags(log.LstdFlags | log.LdateHyphenSeparator) where log.LdateHyphenSeparator would be a new flag) for the sake of backward compatibility.

What did you see instead?

2021/12/15 19:12:34 Hello, world.

Explanation

This has been one of my biggest pet peeve -- as petty as it sounds. I've considered using a different logging libraries, but the truth is, all I want is this feature in the standard library.

Let me explain myself.

I find the date in the following logs:

2021/12/15 19:39:13 Listening on :8080
2021/12/15 19:39:15 Received termination signal, attempting to gracefully shut down
2021/12/15 19:39:15 http: Server closed
2021/12/15 19:39:15 Shutting down janitor   
2021/12/15 19:39:16 Shutting down

significantly more distracting than this:

2021-12-15 19:39:13 Listening on :8080
2021-12-15 19:39:15 Received termination signal, attempting to gracefully shut down
2021-12-15 19:39:15 http: Server closed
2021-12-15 19:39:15 Shutting down janitor   
2021-12-15 19:39:16 Shutting down

I find it easier to read because - doesn't leave the ambiguity that / does with 1 and 7, and after having used Go for a long time and scrolling through millions of lines of logs, ambiguity or not, / makes my eyes pause for slightly longer than - would.

Furthermore, the separator for time is also :, which, like -, has a much smaller max character height than /, making it less visually distracting.

Making the change is extremely trivial -- I don't mind taking care of it, in fact, I'd love to -- but I'd like to know if there are any objections to it. From what I've seen, the log package is extremely barebone, and rightfully so, but I really think that in term of UX, having an easier-to-read date format in the standard library log package would go a long way.

FWIW, if I was the only person impacted, I would have wanted the package to use - as the date separator by default, alas, this would surely break more than one libraries.

Relevant

#6095: Unlike this issue, I actually think that having the timestamp follow ISO8601 would make the whole timestamp even less readable. All I'm interested in is adding a flag to use - instead of / for the date.

@ianlancetaylor ianlancetaylor changed the title log: Add flag to use hyphen instead of slash as separator proposal: log: add flag to use hyphen instead of slash as separator Dec 16, 2021
@gopherbot gopherbot added this to the Proposal milestone Dec 16, 2021
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals Dec 16, 2021
@josharian
Copy link
Contributor

@josharian josharian commented Dec 17, 2021

It seems to me that if we were going to do something like this, we should provide an API to replace the entire time format string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Proposals
Incoming
Development

No branches or pull requests

3 participants