git » log » commit 2f2af16

Change date format to ISO 8601 (yyyy-mm-dd)

author ThinkChaos
2020-05-20 23:25:17 UTC
committer Alberto Bertogli
2020-05-22 00:01:22 UTC
parent 6cd06f6ca2f809ea073d470a945a0babef9904c4

Change date format to ISO 8601 (yyyy-mm-dd)

This patch changes the date format to use ISO 8601 (yyyy-mm-dd), for
readability and consistency.

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Added tests, edited commit message.

log.go +1 -1
log_test.go +1 -1

diff --git a/log.go b/log.go
index 3ada5b2..3985c8c 100644
--- a/log.go
+++ b/log.go
@@ -194,7 +194,7 @@ func (l *Logger) Log(level Level, skip int, format string, a ...interface{}) {
 
 	// Time.
 	if l.logTime {
-		msg = time.Now().Format("20060102 15:04:05.000000 ") + msg
+		msg = time.Now().Format("2006-01-02 15:04:05.000000 ") + msg
 	}
 
 	if !strings.HasSuffix(msg, "\n") {
diff --git a/log_test.go b/log_test.go
index 6443fe9..d6ed221 100644
--- a/log_test.go
+++ b/log_test.go
@@ -50,7 +50,7 @@ func testLogger(t *testing.T, fname string, l *Logger) {
 	l.logTime = true
 	l.Infof("message %d", 1)
 	checkContentsMatch(t, "info-with-time", fname,
-		`^\d{8} ..:..:..\.\d{6} _ log_test.go:....   message 1\n`)
+		`^....-..-.. ..:..:..\.\d{6} _ log_test.go:....   message 1\n`)
 
 	os.Truncate(fname, 0)
 	l.logTime = false